Cleanup: comments, assert align is a power of two
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user