Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-03-02 03:57:39 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-02 03:57:39 +0300
commit490a385c8124dea09c3d06cc0dd546189bc6ec11 (patch)
tree714331abd85897bf2b265e52f4f31e128c2c17c4 /source/blender/blenlib
parentb5d87f802806df6f19d53213d31acbc6f26864b6 (diff)
Cleanup: comments, assert align is a power of two
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/BLI_memarena.c20
1 files changed, 10 insertions, 10 deletions
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);