|
Blender V5.0
|
#include <stdarg.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include "MEM_guardedalloc.h"#include "../../source/blender/blenlib/BLI_strict_flags.h"#include "atomic_ops.h"#include "mallocn_intern.hh"#include "mallocn_intern_function_pointers.hh"Go to the source code of this file.
Macros | |
| #define | MEMHEAD_FROM_PTR(ptr) |
| #define | PTR_FROM_MEMHEAD(memhead) |
| #define | MEMHEAD_ALIGNED_FROM_PTR(ptr) |
| #define | MEMHEAD_IS_ALIGNED(memhead) |
| #define | MEMHEAD_IS_FROM_CPP_NEW(memhead) |
| #define | MEMHEAD_LEN(memhead) |
Enumerations | |
| enum | { MEMHEAD_FLAG_ALIGN = 1 << 0 , MEMHEAD_FLAG_FROM_CPP_NEW = 1 << 1 , MEMHEAD_FLAG_MASK = (1 << 2) - 1 } |
Functions | |
| static void | print_error (const char *message, va_list str_format_args) |
| static void | print_error (const char *message,...) |
| static void | report_error_on_address (const void *vmemh, const char *message,...) |
| size_t | MEM_lockfree_allocN_len (const void *vmemh) |
| void | MEM_lockfree_freeN (void *vmemh, AllocationType allocation_type) |
| void * | MEM_lockfree_dupallocN (const void *vmemh) |
| void * | MEM_lockfree_reallocN_id (void *vmemh, size_t len, const char *str) |
| void * | MEM_lockfree_recallocN_id (void *vmemh, size_t len, const char *str) |
| void * | MEM_lockfree_callocN (size_t len, const char *str) |
| void * | MEM_lockfree_calloc_arrayN (size_t len, size_t size, const char *str) |
| void * | MEM_lockfree_mallocN (size_t len, const char *str) |
| void * | MEM_lockfree_malloc_arrayN (size_t len, size_t size, const char *str) |
| void * | MEM_lockfree_mallocN_aligned (size_t len, size_t alignment, const char *str, const AllocationType allocation_type) |
| static void * | mem_lockfree_malloc_arrayN_aligned (const size_t len, const size_t size, const size_t alignment, const char *str, size_t &r_bytes_num) |
| void * | MEM_lockfree_malloc_arrayN_aligned (const size_t len, const size_t size, const size_t alignment, const char *str) |
| void * | MEM_lockfree_calloc_arrayN_aligned (const size_t len, const size_t size, const size_t alignment, const char *str) |
| void | MEM_lockfree_printmemlist_pydict () |
| void | MEM_lockfree_printmemlist () |
| void | mem_lockfree_clearmemlist () |
| void | MEM_lockfree_callbackmemlist (void(*func)(void *)) |
| void | MEM_lockfree_printmemlist_stats () |
| void | MEM_lockfree_set_error_callback (void(*func)(const char *)) |
| bool | MEM_lockfree_consistency_check () |
| void | MEM_lockfree_set_memory_debug () |
| size_t | MEM_lockfree_get_memory_in_use () |
| uint | MEM_lockfree_get_memory_blocks_in_use () |
| void | MEM_lockfree_reset_peak_memory () |
| size_t | MEM_lockfree_get_peak_memory () |
| const char * | MEM_lockfree_name_ptr (void *vmemh) |
| void | MEM_lockfree_name_ptr_set (void *, const char *) |
Variables | |
| static bool | malloc_debug_memset = false |
| static void(* | error_callback )(const char *) = nullptr |
Memory allocation which keeps track on allocated memory counters
Definition in file mallocn_lockfree_impl.cc.
| #define MEMHEAD_ALIGNED_FROM_PTR | ( | ptr | ) |
Definition at line 76 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_freeN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and report_error_on_address().
| #define MEMHEAD_FROM_PTR | ( | ptr | ) |
Definition at line 74 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_allocN_len(), MEM_lockfree_dupallocN(), MEM_lockfree_freeN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and report_error_on_address().
| #define MEMHEAD_IS_ALIGNED | ( | memhead | ) |
Definition at line 77 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_freeN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and report_error_on_address().
| #define MEMHEAD_IS_FROM_CPP_NEW | ( | memhead | ) |
Definition at line 78 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_freeN(), MEM_lockfree_reallocN_id(), and MEM_lockfree_recallocN_id().
| #define MEMHEAD_LEN | ( | memhead | ) |
Definition at line 79 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_allocN_len(), MEM_lockfree_freeN(), and report_error_on_address().
| #define PTR_FROM_MEMHEAD | ( | memhead | ) |
Definition at line 75 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_callocN(), MEM_lockfree_mallocN(), and MEM_lockfree_mallocN_aligned().
| anonymous enum |
Guardedalloc always allocate multiple of 4 bytes. That means that the lower 2 bits of the len member of #MemHead/#MemHeadAligned data can be used for the bitflags below.
| Enumerator | |
|---|---|
| MEMHEAD_FLAG_ALIGN | This block used aligned allocation, and its 'head' is of #MemHeadAligned type. |
| MEMHEAD_FLAG_FROM_CPP_NEW | This block of memory has been allocated from CPP new (e.g. #MEM_new, or some guardedalloc-overloaded new operator). It mainly checks that MEM_freeN is not directly called on it (#MEM_delete or some guardedalloc-overloaded delete operator should always be used instead). |
| MEMHEAD_FLAG_MASK | |
Definition at line 60 of file mallocn_lockfree_impl.cc.
| size_t MEM_lockfree_allocN_len | ( | const void * | vmemh | ) |
Definition at line 138 of file mallocn_lockfree_impl.cc.
References LIKELY, MEMHEAD_FROM_PTR, and MEMHEAD_LEN.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
| void MEM_lockfree_callbackmemlist | ( | void(* | func )(void *) | ) |
Definition at line 524 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void * MEM_lockfree_calloc_arrayN | ( | size_t | len, |
| size_t | size, | ||
| const char * | str ) |
Definition at line 319 of file mallocn_lockfree_impl.cc.
References len, MEM_lockfree_callocN(), MEM_size_safe_multiply(), memory_usage_current(), print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_lockfree_calloc_arrayN_aligned().
| void * MEM_lockfree_calloc_arrayN_aligned | ( | const size_t | len, |
| const size_t | size, | ||
| const size_t | alignment, | ||
| const char * | str ) |
Definition at line 496 of file mallocn_lockfree_impl.cc.
References len, MEM_lockfree_calloc_arrayN(), mem_lockfree_malloc_arrayN_aligned(), ptr, size(), and str.
| void * MEM_lockfree_callocN | ( | size_t | len, |
| const char * | str ) |
Definition at line 298 of file mallocn_lockfree_impl.cc.
References len, LIKELY, memory_usage_block_alloc(), memory_usage_current(), print_error(), PTR_FROM_MEMHEAD, SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, and str.
Referenced by MEM_lockfree_calloc_arrayN(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
| void mem_lockfree_clearmemlist | ( | void | ) |
Definition at line 520 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| bool MEM_lockfree_consistency_check | ( | void | ) |
Definition at line 548 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void * MEM_lockfree_dupallocN | ( | const void * | vmemh | ) |
Definition at line 181 of file mallocn_lockfree_impl.cc.
References mem_guarded::internal::ALLOC_FREE, MEM_lockfree_allocN_len(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, MEMHEAD_IS_FROM_CPP_NEW, report_error_on_address(), and UNLIKELY.
Referenced by MEM_use_lockfree_allocator().
| void MEM_lockfree_freeN | ( | void * | vmemh, |
| AllocationType | allocation_type ) |
Definition at line 147 of file mallocn_lockfree_impl.cc.
References aligned_free(), free(), free_after_leak_detection_message, leak_detector_has_run, len, malloc_debug_memset, MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, MEMHEAD_IS_FROM_CPP_NEW, MEMHEAD_LEN, MEMHEAD_REAL_PTR, memory_usage_block_free(), mem_guarded::internal::NEW_DELETE, print_error(), report_error_on_address(), and UNLIKELY.
Referenced by MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
| uint MEM_lockfree_get_memory_blocks_in_use | ( | void | ) |
Definition at line 563 of file mallocn_lockfree_impl.cc.
References memory_usage_block_num().
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| size_t MEM_lockfree_get_memory_in_use | ( | void | ) |
Definition at line 558 of file mallocn_lockfree_impl.cc.
References memory_usage_current().
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| size_t MEM_lockfree_get_peak_memory | ( | void | ) |
Definition at line 575 of file mallocn_lockfree_impl.cc.
References memory_usage_peak().
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void * MEM_lockfree_malloc_arrayN | ( | size_t | len, |
| size_t | size, | ||
| const char * | str ) |
Definition at line 376 of file mallocn_lockfree_impl.cc.
References len, MEM_lockfree_mallocN(), MEM_size_safe_multiply(), memory_usage_current(), print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
| void * MEM_lockfree_malloc_arrayN_aligned | ( | const size_t | len, |
| const size_t | size, | ||
| const size_t | alignment, | ||
| const char * | str ) |
Definition at line 487 of file mallocn_lockfree_impl.cc.
References len, mem_lockfree_malloc_arrayN_aligned(), size(), and str.
|
static |
Definition at line 463 of file mallocn_lockfree_impl.cc.
References len, mem_guarded::internal::mem_mallocN, MEM_mallocN_aligned(), MEM_size_safe_multiply(), memory_usage_current(), print_error(), ptr, size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_lockfree_malloc_arrayN_aligned().
| void * MEM_lockfree_mallocN | ( | size_t | len, |
| const char * | str ) |
Definition at line 337 of file mallocn_lockfree_impl.cc.
References len, LIKELY, malloc_debug_memset, memory_usage_block_alloc(), memory_usage_current(), print_error(), PTR_FROM_MEMHEAD, SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by ATTR_NONNULL(), MEM_lockfree_dupallocN(), MEM_lockfree_malloc_arrayN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
| void * MEM_lockfree_mallocN_aligned | ( | size_t | len, |
| size_t | alignment, | ||
| const char * | str, | ||
| const AllocationType | allocation_type ) |
Definition at line 394 of file mallocn_lockfree_impl.cc.
References aligned_malloc(), ALIGNED_MALLOC_MINIMUM_ALIGNMENT, assert, IS_POW2, len, LIKELY, malloc_debug_memset, MEMHEAD_ALIGN_PADDING, MEMHEAD_FLAG_ALIGN, MEMHEAD_FLAG_FROM_CPP_NEW, memory_usage_block_alloc(), memory_usage_current(), mem_guarded::internal::NEW_DELETE, print_error(), PTR_FROM_MEMHEAD, SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_malloc_arrayN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
| const char * MEM_lockfree_name_ptr | ( | void * | vmemh | ) |
Definition at line 581 of file mallocn_lockfree_impl.cc.
Referenced by MEM_use_lockfree_allocator().
| void MEM_lockfree_name_ptr_set | ( | void * | vmemh, |
| const char * | str ) |
Definition at line 590 of file mallocn_lockfree_impl.cc.
Referenced by MEM_use_lockfree_allocator().
| void MEM_lockfree_printmemlist | ( | void | ) |
Definition at line 518 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void MEM_lockfree_printmemlist_pydict | ( | void | ) |
Definition at line 516 of file mallocn_lockfree_impl.cc.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void MEM_lockfree_printmemlist_stats | ( | void | ) |
Definition at line 529 of file mallocn_lockfree_impl.cc.
References memory_usage_current(), memory_usage_peak(), and printf.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void * MEM_lockfree_reallocN_id | ( | void * | vmemh, |
| size_t | len, | ||
| const char * | str ) |
Definition at line 207 of file mallocn_lockfree_impl.cc.
References mem_guarded::internal::ALLOC_FREE, len, LIKELY, MEM_lockfree_allocN_len(), MEM_lockfree_freeN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, MEMHEAD_IS_FROM_CPP_NEW, report_error_on_address(), and str.
Referenced by MEM_use_lockfree_allocator().
| void * MEM_lockfree_recallocN_id | ( | void * | vmemh, |
| size_t | len, | ||
| const char * | str ) |
Definition at line 250 of file mallocn_lockfree_impl.cc.
References mem_guarded::internal::ALLOC_FREE, len, LIKELY, MEM_lockfree_allocN_len(), MEM_lockfree_callocN(), MEM_lockfree_freeN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, MEMHEAD_IS_FROM_CPP_NEW, report_error_on_address(), and str.
Referenced by MEM_use_lockfree_allocator().
| void MEM_lockfree_reset_peak_memory | ( | void | ) |
Definition at line 570 of file mallocn_lockfree_impl.cc.
References memory_usage_peak_reset().
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void MEM_lockfree_set_error_callback | ( | void(* | func )(const char *) | ) |
Definition at line 543 of file mallocn_lockfree_impl.cc.
References error_callback.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
| void MEM_lockfree_set_memory_debug | ( | void | ) |
Definition at line 553 of file mallocn_lockfree_impl.cc.
References malloc_debug_memset.
Referenced by MEM_lockfree_calloc_arrayN_aligned(), and MEM_use_lockfree_allocator().
|
static |
Definition at line 85 of file mallocn_lockfree_impl.cc.
References error_callback, and error_callback.
Referenced by MEM_lockfree_calloc_arrayN(), MEM_lockfree_callocN(), MEM_lockfree_freeN(), MEM_lockfree_malloc_arrayN(), mem_lockfree_malloc_arrayN_aligned(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), print_error(), and report_error_on_address().
|
static |
Definition at line 100 of file mallocn_lockfree_impl.cc.
References print_error().
|
static |
Definition at line 112 of file mallocn_lockfree_impl.cc.
References len, MEM_trigger_error_on_memory_block(), MEMHEAD_ALIGN_PADDING, MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, MEMHEAD_LEN, MEMHEAD_REAL_PTR, print_error(), size(), and UNLIKELY.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_freeN(), MEM_lockfree_reallocN_id(), and MEM_lockfree_recallocN_id().
|
static |
Definition at line 54 of file mallocn_lockfree_impl.cc.
Referenced by print_error().
|
static |
Definition at line 52 of file mallocn_lockfree_impl.cc.