diff options
author | MaximB ProductEngine <mberezhnoy@productengine.com> | 2012-10-18 22:29:02 +0300 |
---|---|---|
committer | MaximB ProductEngine <mberezhnoy@productengine.com> | 2012-10-18 22:29:02 +0300 |
commit | c43cfcdcbd243410e2f780f58f93100e96fc996c (patch) | |
tree | d5daa0187843a9302c1011937d452d40692d0d1a /indra/llcommon/llmemory.h | |
parent | c0b60841ce14a1c449ede17284d2aa6939322be3 (diff) | |
parent | f9c068462f379a4678e59090a066cfa173504c6b (diff) |
merge into latest changes
Diffstat (limited to 'indra/llcommon/llmemory.h')
-rw-r--r-- | indra/llcommon/llmemory.h | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 08e2a2caa6..40cde485cf 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -27,6 +27,13 @@ #define LLMEMORY_H #include "llmemtype.h" + +#if LL_WINDOWS && LL_DEBUG +#define LL_CHECK_MEMORY llassert(_CrtCheckMemory()); +#else +#define LL_CHECK_MEMORY +#endif + inline void* ll_aligned_malloc( size_t size, int align ) { void* mem = malloc( size + (align - 1) + sizeof(void*) ); @@ -58,33 +65,39 @@ inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed wi #endif } -inline void* ll_aligned_realloc_16(void* ptr, size_t size) // returned hunk MUST be freed with ll_aligned_free_16(). +inline void ll_aligned_free_16(void *p) { #if defined(LL_WINDOWS) - return _aligned_realloc(ptr, size, 16); + _aligned_free(p); #elif defined(LL_DARWIN) - return realloc(ptr,size); // default osx malloc is 16 byte aligned. + return free(p); #else - // The realloc alignment test is skipped on Linux because the ll_aligned_realloc_16() - // function is not implemented to ensure alignment (see alignment_test.cpp) - return realloc(ptr,size); // FIXME not guaranteed to be aligned. + free(p); // posix_memalign() is compatible with heap deallocator #endif } -inline void ll_aligned_free_16(void *p) +inline void* ll_aligned_realloc_16(void* ptr, size_t size, size_t old_size) // returned hunk MUST be freed with ll_aligned_free_16(). { #if defined(LL_WINDOWS) - _aligned_free(p); + return _aligned_realloc(ptr, size, 16); #elif defined(LL_DARWIN) - return free(p); + return realloc(ptr,size); // default osx malloc is 16 byte aligned. #else - free(p); // posix_memalign() is compatible with heap deallocator + //FIXME: memcpy is SLOW + void* ret = ll_aligned_malloc_16(size); + if (ptr) + { + memcpy(ret, ptr, old_size); + ll_aligned_free_16(ptr); + } + return ret; #endif } + #else // USE_TCMALLOC // ll_aligned_foo_16 are not needed with tcmalloc #define ll_aligned_malloc_16 malloc -#define ll_aligned_realloc_16 realloc +#define ll_aligned_realloc_16(a,b,c) realloc(a,b) #define ll_aligned_free_16 free #endif // USE_TCMALLOC |