33 #ifndef __MEM_GUARDEDALLOC_H__
34 #define __MEM_GUARDEDALLOC_H__
37 #include "../../source/blender/blenlib/BLI_compiler_attrs.h"
38 #include "../../source/blender/blenlib/BLI_sys_types.h"
60 extern short (*MEM_testN)(
void *vmemh);
74 extern void *(*MEM_reallocN_id)(
void *vmemh,
82 extern void *(*MEM_recallocN_id)(
void *vmemh,
87 #define MEM_reallocN(vmemh, len) MEM_reallocN_id(vmemh, len, __func__)
88 #define MEM_recallocN(vmemh, len) MEM_recallocN_id(vmemh, len, __func__)
176 # define MEM_SAFE_FREE(v) \
178 typeof(&(v)) _v = &(v); \
181 MEM_freeN((void *)*_v); \
186 # define MEM_SAFE_FREE(v) \
188 void **_v = (void **)&(v); \
197 #define MEM_SIZE_OVERHEAD sizeof(size_t)
198 #define MEM_SIZE_OPTIMAL(size) ((size)-MEM_SIZE_OVERHEAD)
201 extern const char *(*MEM_name_ptr)(
void *vmemh);
248 # include <type_traits>
262 template<
typename T,
typename... Args>
263 inline T *MEM_new(
const char *allocation_name, Args &&...args)
266 return new (
buffer)
T(std::forward<Args>(args)...);
275 template<
typename T>
inline T *MEM_cnew(
const char *allocation_name)
277 static_assert(std::is_trivial_v<T>,
"For non-trivial types, MEM_new should be used.");
278 return static_cast<T *
>(
MEM_callocN(
sizeof(
T), allocation_name));
291 template<
typename T>
inline T *MEM_cnew(
const char *allocation_name,
const T &other)
293 static_assert(std::is_trivial_v<T>,
"For non-trivial types, MEM_new should be used.");
294 T *new_object =
static_cast<T *
>(
MEM_mallocN(
sizeof(
T), allocation_name));
295 memcpy(new_object, &other,
sizeof(
T));
303 template<
typename T>
inline void MEM_delete(
const T *
ptr)
305 if (
ptr ==
nullptr) {
315 # define MEM_CXX_CLASS_ALLOC_FUNCS(_id) \
317 void *operator new(size_t num_bytes) \
319 return MEM_mallocN(num_bytes, _id); \
321 void operator delete(void *mem) \
327 void *operator new[](size_t num_bytes) \
329 return MEM_mallocN(num_bytes, _id "[]"); \
331 void operator delete[](void *mem) \
337 void *operator new(size_t
, void *ptr) \
343 void operator delete(void * , void * ) \
#define ATTR_WARN_UNUSED_RESULT
#define ATTR_ALLOC_SIZE(...)
void MEM_use_guarded_allocator(void)
void MEM_use_memleak_detection(bool enabled)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void(* MEM_freeN)(void *vmemh)
void(* MEM_reset_peak_memory)(void)
void MEM_enable_fail_on_memleak(void)
size_t(* MEM_get_memory_in_use)(void)
void(* MEM_printmemlist_stats)(void)
void(* MEM_set_memory_debug)(void)
size_t(* MEM_get_peak_memory)(void) ATTR_WARN_UNUSED_RESULT
void MEM_init_memleak_detection(void)
void *(* MEM_mallocN)(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void(* MEM_set_error_callback)(void(*func)(const char *))
size_t(* MEM_allocN_len)(const void *vmemh) ATTR_WARN_UNUSED_RESULT
void MEM_use_lockfree_allocator(void)
bool(* MEM_consistency_check)(void)
unsigned int(* MEM_get_memory_blocks_in_use)(void)
void(* MEM_printmemlist_pydict)(void)
void *(* MEM_callocN)(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void *(* ATTR_NONNULL)(3)
Iterator New.
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void *(* MEM_mallocN_aligned)(size_t len, size_t alignment, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3)
void(* MEM_callbackmemlist)(void(*func)(void *))
void(* MEM_printmemlist)(void)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SyclQueue void void size_t num_bytes void
ccl_global float * buffer