Blender V5.0
mallocn_intern.hh File Reference
#include <malloc.h>
#include "mallocn_inline.hh"

Go to the source code of this file.

Macros

#define UNUSED(x)
#define USE_MALLOC_USABLE_SIZE   /* internal, when we have malloc_usable_size() */
#define SIZET_FORMAT   "%zu"
#define SIZET_ARG(a)
#define SIZET_ALIGN_4(len)
#define LIKELY(x)
#define UNLIKELY(x)
#define MEM_INLINE   static inline
#define IS_POW2(a)
#define MEMHEAD_ALIGN_PADDING(alignment)
#define MEMHEAD_REAL_PTR(memh)
#define ALIGNED_MALLOC_MINIMUM_ALIGNMENT   sizeof(void *)

Functions

void * aligned_malloc (size_t size, size_t alignment)
void aligned_free (void *ptr)
void memory_usage_init (void)
void memory_usage_block_alloc (size_t size)
void memory_usage_block_free (size_t size)
size_t memory_usage_block_num (void)
size_t memory_usage_current (void)
size_t memory_usage_peak (void)
void memory_usage_peak_reset (void)
size_t MEM_lockfree_allocN_len (const void *vmemh) ATTR_WARN_UNUSED_RESULT
void MEM_lockfree_freeN (void *vmemh, mem_guarded::internal::AllocationType allocation_type)
void * MEM_lockfree_dupallocN (const void *vmemh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * MEM_lockfree_reallocN_id (void *vmemh, size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
void * MEM_lockfree_recallocN_id (void *vmemh, size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
void * MEM_lockfree_callocN (size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void * MEM_lockfree_calloc_arrayN (size_t len, size_t size, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * MEM_lockfree_mallocN (size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void * MEM_lockfree_malloc_arrayN (size_t len, size_t size, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * MEM_lockfree_mallocN_aligned (size_t len, size_t alignment, const char *str, mem_guarded::internal::AllocationType allocation_type) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3)
void * MEM_lockfree_malloc_arrayN_aligned (size_t len, size_t size, size_t alignment, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * MEM_lockfree_calloc_arrayN_aligned (size_t len, size_t size, size_t alignment, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void MEM_lockfree_printmemlist_pydict (void)
void MEM_lockfree_printmemlist (void)
void MEM_lockfree_callbackmemlist (void(*func)(void *))
void MEM_lockfree_printmemlist_stats (void)
void MEM_lockfree_set_error_callback (void(*func)(const char *))
bool MEM_lockfree_consistency_check (void)
void MEM_lockfree_set_memory_debug (void)
size_t MEM_lockfree_get_memory_in_use (void)
unsigned int MEM_lockfree_get_memory_blocks_in_use (void)
void MEM_lockfree_reset_peak_memory (void)
size_t MEM_lockfree_get_peak_memory (void) ATTR_WARN_UNUSED_RESULT
void mem_lockfree_clearmemlist (void)
const char * MEM_lockfree_name_ptr (void *vmemh)
void MEM_lockfree_name_ptr_set (void *vmemh, const char *str)
size_t MEM_guarded_allocN_len (const void *vmemh) ATTR_WARN_UNUSED_RESULT
void MEM_guarded_freeN (void *vmemh, mem_guarded::internal::AllocationType allocation_type)
void * MEM_guarded_dupallocN (const void *vmemh) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * MEM_guarded_reallocN_id (void *vmemh, size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
void * MEM_guarded_recallocN_id (void *vmemh, size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(2)
void * MEM_guarded_callocN (size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void * MEM_guarded_calloc_arrayN (size_t len, size_t size, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * MEM_guarded_mallocN (size_t len, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void * MEM_guarded_malloc_arrayN (size_t len, size_t size, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * MEM_guarded_mallocN_aligned (size_t len, size_t alignment, const char *str, mem_guarded::internal::AllocationType allocation_type) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3)
void * MEM_guarded_malloc_arrayN_aligned (size_t len, size_t size, size_t alignment, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void * MEM_guarded_calloc_arrayN_aligned (size_t len, size_t size, size_t alignment, const char *str) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void MEM_guarded_printmemlist_pydict (void)
void MEM_guarded_printmemlist (void)
void MEM_guarded_callbackmemlist (void(*func)(void *))
void MEM_guarded_printmemlist_stats (void)
void MEM_guarded_set_error_callback (void(*func)(const char *))
bool MEM_guarded_consistency_check (void)
void MEM_guarded_set_memory_debug (void)
size_t MEM_guarded_get_memory_in_use (void)
unsigned int MEM_guarded_get_memory_blocks_in_use (void)
void MEM_guarded_reset_peak_memory (void)
size_t MEM_guarded_get_peak_memory (void) ATTR_WARN_UNUSED_RESULT
void mem_guarded_clearmemlist (void)
const char * MEM_guarded_name_ptr (void *vmemh)
void MEM_guarded_name_ptr_set (void *vmemh, const char *str)
Untyped Allocation API.

Defines the 'C-style' part of the API, where memory management is fully untyped (i.e. done with void pointers and explicit size values).

This API should usually not be used anymore in C++ code, unless some form of raw memory management is necessary (e.g. for allocation of various ID types based on their IDTypeInfo::struct_size data).

void ATTR_NONNULL (3)
void ATTR_NONNULL (4)

Variables

bool leak_detector_has_run
char free_after_leak_detection_message []
void(* mem_clearmemlist )(void)

Macro Definition Documentation

◆ ALIGNED_MALLOC_MINIMUM_ALIGNMENT

#define ALIGNED_MALLOC_MINIMUM_ALIGNMENT   sizeof(void *)

◆ IS_POW2

#define IS_POW2 ( a)
Value:
(((a) & ((a) - 1)) == 0)

Definition at line 72 of file mallocn_intern.hh.

Referenced by MEM_guarded_mallocN_aligned(), and MEM_lockfree_mallocN_aligned().

◆ LIKELY

#define LIKELY ( x)
Value:

Definition at line 52 of file mallocn_intern.hh.

◆ MEM_INLINE

#define MEM_INLINE   static inline

Definition at line 69 of file mallocn_intern.hh.

Referenced by MEM_size_safe_multiply(), and MEM_trigger_error_on_memory_block().

◆ MEMHEAD_ALIGN_PADDING

#define MEMHEAD_ALIGN_PADDING ( alignment)
Value:
((size_t)alignment - (sizeof(MemHeadAligned) % (size_t)alignment))

Definition at line 75 of file mallocn_intern.hh.

Referenced by MEM_guarded_mallocN_aligned(), MEM_lockfree_mallocN_aligned(), report_error_on_address(), and report_error_on_address().

◆ MEMHEAD_REAL_PTR

#define MEMHEAD_REAL_PTR ( memh)
Value:
((char *)memh - MEMHEAD_ALIGN_PADDING(memh->alignment))
#define MEMHEAD_ALIGN_PADDING(alignment)

Definition at line 79 of file mallocn_intern.hh.

Referenced by MEM_lockfree_freeN(), rem_memblock(), report_error_on_address(), and report_error_on_address().

◆ SIZET_ALIGN_4

#define SIZET_ALIGN_4 ( len)

◆ SIZET_ARG

◆ SIZET_FORMAT

◆ UNLIKELY

#define UNLIKELY ( x)
Value:
(x)

Definition at line 53 of file mallocn_intern.hh.

◆ UNUSED

#define UNUSED ( x)
Value:
UNUSED_##x

Definition at line 16 of file mallocn_intern.hh.

◆ USE_MALLOC_USABLE_SIZE

#define USE_MALLOC_USABLE_SIZE   /* internal, when we have malloc_usable_size() */

Definition at line 20 of file mallocn_intern.hh.

Function Documentation

◆ aligned_free()

void aligned_free ( void * ptr)

Definition at line 104 of file mallocn.cc.

References free(), and ptr.

Referenced by MEM_lockfree_freeN(), and rem_memblock().

◆ aligned_malloc()

void * aligned_malloc ( size_t size,
size_t alignment )

◆ ATTR_NONNULL() [1/2]

◆ ATTR_NONNULL() [2/2]

void * ATTR_NONNULL ( 4 )

References ATTR_ALLOC_SIZE, and ATTR_NONNULL.

◆ MEM_guarded_allocN_len()

size_t MEM_guarded_allocN_len ( const void * vmemh)

Definition at line 313 of file mallocn_guarded_impl.cc.

Referenced by MEM_use_guarded_allocator().

◆ MEM_guarded_callbackmemlist()

void MEM_guarded_callbackmemlist ( void(* func )(void *))

◆ MEM_guarded_calloc_arrayN()

void * MEM_guarded_calloc_arrayN ( size_t len,
size_t size,
const char * str )

◆ MEM_guarded_calloc_arrayN_aligned()

◆ MEM_guarded_callocN()

void * MEM_guarded_callocN ( size_t len,
const char * str )

◆ mem_guarded_clearmemlist()

void mem_guarded_clearmemlist ( void )

Definition at line 1034 of file mallocn_guarded_impl.cc.

References membase.

Referenced by MEM_guarded_calloc_arrayN_aligned(), and MEM_use_guarded_allocator().

◆ MEM_guarded_consistency_check()

bool MEM_guarded_consistency_check ( void )

◆ MEM_guarded_dupallocN()

◆ MEM_guarded_freeN()

◆ MEM_guarded_get_memory_blocks_in_use()

unsigned int MEM_guarded_get_memory_blocks_in_use ( void )

◆ MEM_guarded_get_memory_in_use()

size_t MEM_guarded_get_memory_in_use ( void )

◆ MEM_guarded_get_peak_memory()

size_t MEM_guarded_get_peak_memory ( void )

◆ MEM_guarded_malloc_arrayN()

void * MEM_guarded_malloc_arrayN ( size_t len,
size_t size,
const char * str )

◆ MEM_guarded_malloc_arrayN_aligned()

void * MEM_guarded_malloc_arrayN_aligned ( size_t len,
size_t size,
size_t alignment,
const char * str )

◆ MEM_guarded_mallocN()

◆ MEM_guarded_mallocN_aligned()

◆ MEM_guarded_name_ptr()

const char * MEM_guarded_name_ptr ( void * vmemh)

Definition at line 1396 of file mallocn_guarded_impl.cc.

Referenced by MEM_use_guarded_allocator().

◆ MEM_guarded_name_ptr_set()

void MEM_guarded_name_ptr_set ( void * vmemh,
const char * str )

Definition at line 1407 of file mallocn_guarded_impl.cc.

References MEMNEXT, and str.

Referenced by MEM_use_guarded_allocator().

◆ MEM_guarded_printmemlist()

void MEM_guarded_printmemlist ( void )

◆ MEM_guarded_printmemlist_pydict()

void MEM_guarded_printmemlist_pydict ( void )

◆ MEM_guarded_printmemlist_stats()

◆ MEM_guarded_reallocN_id()

void * MEM_guarded_reallocN_id ( void * vmemh,
size_t len,
const char * str )

◆ MEM_guarded_recallocN_id()

void * MEM_guarded_recallocN_id ( void * vmemh,
size_t len,
const char * str )

◆ MEM_guarded_reset_peak_memory()

void MEM_guarded_reset_peak_memory ( void )

◆ MEM_guarded_set_error_callback()

void MEM_guarded_set_error_callback ( void(* func )(const char *))

◆ MEM_guarded_set_memory_debug()

void MEM_guarded_set_memory_debug ( void )

◆ MEM_lockfree_allocN_len()

size_t MEM_lockfree_allocN_len ( const void * vmemh)

◆ MEM_lockfree_callbackmemlist()

void MEM_lockfree_callbackmemlist ( void(* func )(void *))

◆ MEM_lockfree_calloc_arrayN()

void * MEM_lockfree_calloc_arrayN ( size_t len,
size_t size,
const char * str )

◆ MEM_lockfree_calloc_arrayN_aligned()

◆ MEM_lockfree_callocN()

◆ mem_lockfree_clearmemlist()

void mem_lockfree_clearmemlist ( void )

◆ MEM_lockfree_consistency_check()

bool MEM_lockfree_consistency_check ( void )

◆ MEM_lockfree_dupallocN()

◆ MEM_lockfree_freeN()

◆ MEM_lockfree_get_memory_blocks_in_use()

unsigned int MEM_lockfree_get_memory_blocks_in_use ( void )

◆ MEM_lockfree_get_memory_in_use()

size_t MEM_lockfree_get_memory_in_use ( void )

◆ MEM_lockfree_get_peak_memory()

size_t MEM_lockfree_get_peak_memory ( void )

◆ MEM_lockfree_malloc_arrayN()

void * MEM_lockfree_malloc_arrayN ( size_t len,
size_t size,
const char * str )

◆ MEM_lockfree_malloc_arrayN_aligned()

void * MEM_lockfree_malloc_arrayN_aligned ( size_t len,
size_t size,
size_t alignment,
const char * str )

◆ MEM_lockfree_mallocN()

◆ MEM_lockfree_mallocN_aligned()

◆ MEM_lockfree_name_ptr()

const char * MEM_lockfree_name_ptr ( void * vmemh)

Definition at line 581 of file mallocn_lockfree_impl.cc.

Referenced by MEM_use_lockfree_allocator().

◆ MEM_lockfree_name_ptr_set()

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().

◆ MEM_lockfree_printmemlist()

void MEM_lockfree_printmemlist ( void )

◆ MEM_lockfree_printmemlist_pydict()

void MEM_lockfree_printmemlist_pydict ( void )

◆ MEM_lockfree_printmemlist_stats()

void MEM_lockfree_printmemlist_stats ( void )

◆ MEM_lockfree_reallocN_id()

◆ MEM_lockfree_recallocN_id()

◆ MEM_lockfree_reset_peak_memory()

void MEM_lockfree_reset_peak_memory ( void )

◆ MEM_lockfree_set_error_callback()

void MEM_lockfree_set_error_callback ( void(* func )(const char *))

◆ MEM_lockfree_set_memory_debug()

void MEM_lockfree_set_memory_debug ( void )

◆ memory_usage_block_alloc()

void memory_usage_block_alloc ( size_t size)

◆ memory_usage_block_free()

void memory_usage_block_free ( size_t size)

Definition at line 212 of file memory_usage.cc.

References get_global(), get_local_data(), LIKELY, size(), and use_local_counters.

Referenced by MEM_lockfree_freeN().

◆ memory_usage_block_num()

size_t memory_usage_block_num ( void )

Definition at line 229 of file memory_usage.cc.

References get_global(), and lock.

Referenced by MEM_lockfree_get_memory_blocks_in_use().

◆ memory_usage_current()

◆ memory_usage_init()

void memory_usage_init ( void )

Definition at line 182 of file memory_usage.cc.

References get_local_data().

Referenced by MEM_init_memleak_detection().

◆ memory_usage_peak()

size_t memory_usage_peak ( void )

Get the approximate peak memory usage since the last call to memory_usage_peak_reset. This is approximate, because the peak usage is not updated after every allocation (see peak_update_threshold).

In the worst case, the peak memory usage is underestimated by peak_update_threshold * #threads. After large allocations (larger than the threshold), the peak usage is always updated so those allocations will always be taken into account.

Definition at line 255 of file memory_usage.cc.

References get_global(), and update_global_peak().

Referenced by MEM_lockfree_get_peak_memory(), and MEM_lockfree_printmemlist_stats().

◆ memory_usage_peak_reset()

void memory_usage_peak_reset ( void )

Definition at line 262 of file memory_usage.cc.

References get_global(), and memory_usage_current().

Referenced by MEM_lockfree_reset_peak_memory().

Variable Documentation

◆ free_after_leak_detection_message

char free_after_leak_detection_message[]
extern

Definition at line 19 of file leak_detector.cc.

Referenced by MEM_guarded_freeN(), and MEM_lockfree_freeN().

◆ leak_detector_has_run

bool leak_detector_has_run
extern

Definition at line 18 of file leak_detector.cc.

Referenced by MEM_guarded_freeN(), and MEM_lockfree_freeN().

◆ mem_clearmemlist

void(* mem_clearmemlist) (void) ( void )
extern

Clear the listbase of allocated memory blocks.

WARNING: This will make the whole guardedalloc system fully inconsistent. It is only indented to be called in one place: the destructor of the #MemLeakPrinter class, which is only instantiated once as a static variable by MEM_init_memleak_detection, and therefore destructed once at program exit.

Definition at line 75 of file mallocn.cc.

Referenced by MEM_use_guarded_allocator(), and MEM_use_lockfree_allocator().