diff options
Diffstat (limited to 'intern/guardedalloc/MEM_guardedalloc.h')
-rw-r--r-- | intern/guardedalloc/MEM_guardedalloc.h | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 83d6549218a..4bb8cba6810 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -97,10 +97,10 @@ extern "C" { void *MEM_dupallocN(void *vmemh) WARN_UNUSED; /** - * Reallocates a block of memory, and returns pointer to the newly - * allocated block, the old one is freed. this is not as optimized - * as a system realloc but just makes a new allocation and copies - * over from existing memory. */ + * Reallocates a block of memory, and returns pointer to the newly + * allocated block, the old one is freed. this is not as optimized + * as a system realloc but just makes a new allocation and copies + * over from existing memory. */ void *MEM_reallocN(void *vmemh, size_t len) WARN_UNUSED; /** @@ -110,13 +110,13 @@ extern "C" { void *MEM_callocN(size_t len, const char * str) WARN_UNUSED; /** Allocate a block of memory of size len, with tag name str. The - * name must be a static, because only a pointer to it is stored ! - * */ + * name must be a static, because only a pointer to it is stored ! + * */ void *MEM_mallocN(size_t len, const char * str) WARN_UNUSED; /** Same as callocN, clears memory and uses mmap (disk cached) if supported. - Can be free'd with MEM_freeN as usual. - * */ + * Can be free'd with MEM_freeN as usual. + * */ void *MEM_mapallocN(size_t len, const char * str) WARN_UNUSED; /** Print a list of the names and sizes of all allocated memory @@ -143,7 +143,7 @@ extern "C" { int MEM_check_memory_integrity(void); /** Set thread locking functions for safe memory allocation from multiple - threads, pass NULL pointers to disable thread locking again. */ + * threads, pass NULL pointers to disable thread locking again. */ void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void)); /** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */ @@ -167,10 +167,31 @@ extern "C" { #ifndef NDEBUG const char *MEM_name_ptr(void *vmemh); #endif - + #ifdef __cplusplus -} +/* alloc funcs for C++ only */ +#define MEM_CXX_CLASS_ALLOC_FUNCS(_id) \ +public: \ + void *operator new(size_t num_bytes) { \ + return MEM_mallocN(num_bytes, _id); \ + } \ + void operator delete(void *mem) { \ + if (mem) \ + MEM_freeN(mem); \ + } \ + void *operator new[](size_t num_bytes) { \ + return MEM_mallocN(num_bytes, _id "[]"); \ + } \ + void operator delete[](void *mem) { \ + if (mem) \ + MEM_freeN(mem); \ + } \ + #endif + +#ifdef __cplusplus +} #endif +#endif |