19#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
20int gNumAlignedAllocs = 0;
21int gNumAlignedFree = 0;
22int gTotalBytesAlignedAllocs = 0;
27 char* data = (
char*) malloc(
size);
40#if defined(BT_HAS_ALIGNED_ALLOCATOR)
44 return _aligned_malloc(
size, (
size_t)alignment);
51#elif defined(__CELLOS_LV2__)
56 return memalign(alignment,
size);
69 real = (
char *)
sAllocFunc(
size +
sizeof(
void *) + (alignment - 1));
73 *((
void **)(ret)-1) = (
void *)(real);
80 memset((
char*) ret, 0,
size);
90 real = *((
void **)(ptr)-1);
111#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
113static int allocations_id[10241024];
114static int allocations_bytes[10241024];
115static int mynumallocs = 0;
118int btDumpMemoryLeaks()
122 for (
int i = 0; i < mynumallocs; i++)
124 printf(
"Error: leaked memory of allocation #%d (%d bytes)\n", allocations_id[i], allocations_bytes[i]);
125 totalLeak += allocations_bytes[i];
129 printf(
"Error: memory leaks: %d allocations were not freed and leaked together %d bytes\n", mynumallocs, totalLeak);
136struct btDebugPtrMagic
150 printf(
"Whaat? size==0");
153 static int allocId = 0;
168 gTotalBytesAlignedAllocs +=
size;
171 int sz4prt = 4 *
sizeof(
void *);
179 p.cptr -=
sizeof(
void *);
180 *p.vptrptr = (
void *)real;
181 p.cptr -=
sizeof(
void *);
183 p.cptr -=
sizeof(
void *);
186 allocations_id[mynumallocs] = allocId;
187 allocations_bytes[mynumallocs] =
size;
192 ret = (
void *)(real);
195 printf(
"allocation %d at address %x, from %s,line %d, size %d (total allocated = %d)\n", allocId, real, filename, line,
size, gTotalBytesAlignedAllocs);
198 int *ptr = (
int *)ret;
213 p.cptr -=
sizeof(
void *);
215 p.cptr -=
sizeof(
void *);
217 p.cptr -=
sizeof(
void *);
218 int allocId = *p.iptr;
222 for (
int i = 0; i < mynumallocs; i++)
224 if (allocations_id[i] == allocId)
226 allocations_id[i] = allocations_id[mynumallocs - 1];
227 allocations_bytes[i] = allocations_bytes[mynumallocs - 1];
234 gTotalBytesAlignedAllocs -=
size;
236 int diff = gNumAlignedAllocs - gNumAlignedFree;
237 printf(
"free %d at address %x, from %s,line %d, size %d (total remain = %d in %d non-freed allocations)\n", allocId, real, filename, line,
size, gTotalBytesAlignedAllocs, diff);
static btAlignedAllocFunc * sAlignedAllocFunc
static void btAlignedFreeDefault(void *ptr)
static btAllocFunc * sAllocFunc
void * btAlignedAllocInternal(size_t size, int alignment)
we probably replace this with our own aligned memory allocator so we replace _aligned_malloc and _ali...
static void * btAlignedAllocDefault(size_t size, int alignment)
static void * btAllocDefault(size_t size)
void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc)
If the developer has already an custom aligned allocator, then btAlignedAllocSetCustomAligned can be ...
static void btFreeDefault(void *ptr)
static btFreeFunc * sFreeFunc
void btAlignedFreeInternal(void *ptr)
static btAlignedFreeFunc * sAlignedFreeFunc
void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc)
The developer can let all Bullet memory allocations go through a custom memory allocator,...
void() btFreeFunc(void *memblock)
void *() btAllocFunc(size_t size)
void *() btAlignedAllocFunc(size_t size, int alignment)
void() btAlignedFreeFunc(void *memblock)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
T * btAlignPointer(T *unalignedPtr, size_t alignment)
align a pointer to the provided alignment, upwards