[Bf-blender-cvs] [490a385c812] master: Cleanup: comments, assert align is a power of two
Campbell Barton
noreply at git.blender.org
Sat Mar 2 01:59:16 CET 2019
Commit: 490a385c8124dea09c3d06cc0dd546189bc6ec11
Author: Campbell Barton
Date: Sat Mar 2 11:57:39 2019 +1100
Branches: master
https://developer.blender.org/rB490a385c8124dea09c3d06cc0dd546189bc6ec11
Cleanup: comments, assert align is a power of two
===================================================================
M source/blender/blenlib/intern/BLI_memarena.c
===================================================================
diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c
index 2521320da97..8be64a44d2c 100644
--- a/source/blender/blenlib/intern/BLI_memarena.c
+++ b/source/blender/blenlib/intern/BLI_memarena.c
@@ -15,12 +15,11 @@
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
- * Efficient memory allocation for lots of similar small chunks.
*/
/** \file
* \ingroup bli
- * \brief Memory arena ADT.
+ * \brief Efficient memory allocation for many small chunks.
* \section aboutmemarena Memory Arena
*
* Memory arena's are commonly used when the program
@@ -54,8 +53,8 @@
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
# include "sanitizer/asan_interface.h"
#else
-# define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
-# define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
+# define ASAN_POISON_MEMORY_REGION(addr, size) UNUSED_VARS(addr, size)
+# define ASAN_UNPOISON_MEMORY_REGION(addr, size) UNUSED_VARS(addr, size)
#endif
struct MemBuf {
@@ -107,7 +106,9 @@ void BLI_memarena_use_malloc(MemArena *ma)
void BLI_memarena_use_align(struct MemArena *ma, const size_t align)
{
- /* align should be a power of two */
+ /* Align must be a power of two. */
+ BLI_assert((align & (align - 1)) == 0);
+
ma->align = align;
}
@@ -120,10 +121,10 @@ void BLI_memarena_free(MemArena *ma)
MEM_freeN(ma);
}
-/* amt must be power of two */
+/** Pad num up by \a amt (must be power of two). */
#define PADUP(num, amt) (((num) + ((amt) - 1)) & ~((amt) - 1))
-/* align alloc'ed memory (needed if align > 8) */
+/** Align alloc'ed memory (needed if `align > 8`). */
static void memarena_curbuf_align(MemArena *ma)
{
unsigned char *tmp;
@@ -137,8 +138,7 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
{
void *ptr;
- /* ensure proper alignment by rounding
- * size up to multiple of 8 */
+ /* Ensure proper alignment by rounding size up to multiple of 8. */
size = PADUP(size, ma->align);
if (UNLIKELY(size > ma->cursize)) {
@@ -174,7 +174,7 @@ void *BLI_memarena_calloc(MemArena *ma, size_t size)
{
void *ptr;
- /* no need to use this function call if we're calloc'ing by default */
+ /* No need to use this function call if we're calloc'ing by default. */
BLI_assert(ma->use_calloc == false);
ptr = BLI_memarena_alloc(ma, size);
More information about the Bf-blender-cvs
mailing list