18 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS 19 int gNumAlignedAllocs = 0;
20 int gNumAlignedFree = 0;
21 int gTotalBytesAlignedAllocs = 0;
22 #endif //BT_DEBUG_MEMORY_ALLOCATIONST_DEBUG_ALLOCATIONS 37 #if defined(BT_HAS_ALIGNED_ALLOCATOR) 41 return _aligned_malloc(
size, (
size_t)alignment);
48 #elif defined(__CELLOS_LV2__) 53 return memalign(alignment,
size);
66 real = (
char *)
sAllocFunc(
size +
sizeof(
void *) + (alignment - 1));
70 *((
void **)(ret)-1) = (
void *)(real);
85 real = *((
void **)(ptr)-1);
106 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS 108 static int allocations_id[10241024];
109 static int allocations_bytes[10241024];
110 static int mynumallocs = 0;
113 int btDumpMemoryLeaks()
117 for (
int i = 0; i < mynumallocs; i++)
119 printf(
"Error: leaked memory of allocation #%d (%d bytes)\n", allocations_id[i], allocations_bytes[i]);
120 totalLeak += allocations_bytes[i];
124 printf(
"Error: memory leaks: %d allocations were not freed and leaked together %d bytes\n", mynumallocs, totalLeak);
131 struct btDebugPtrMagic
145 printf(
"Whaat? size==0");
148 static int allocId = 0;
163 gTotalBytesAlignedAllocs +=
size;
166 int sz4prt = 4 *
sizeof(
void *);
174 p.cptr -=
sizeof(
void *);
175 *p.vptrptr = (
void *)real;
176 p.cptr -=
sizeof(
void *);
178 p.cptr -=
sizeof(
void *);
181 allocations_id[mynumallocs] = allocId;
182 allocations_bytes[mynumallocs] =
size;
187 ret = (
void *)(real);
190 printf(
"allocation %d at address %x, from %s,line %d, size %d (total allocated = %d)\n", allocId, real, filename, line,
size, gTotalBytesAlignedAllocs);
193 int *ptr = (
int *)ret;
208 p.cptr -=
sizeof(
void *);
210 p.cptr -=
sizeof(
void *);
212 p.cptr -=
sizeof(
void *);
213 int allocId = *p.iptr;
217 for (
int i = 0; i < mynumallocs; i++)
219 if (allocations_id[i] == allocId)
221 allocations_id[i] = allocations_id[mynumallocs - 1];
222 allocations_bytes[i] = allocations_bytes[mynumallocs - 1];
229 gTotalBytesAlignedAllocs -=
size;
231 int diff = gNumAlignedAllocs - gNumAlignedFree;
232 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);
242 #else //BT_DEBUG_MEMORY_ALLOCATIONS 263 #endif //BT_DEBUG_MEMORY_ALLOCATIONS void *() btAlignedAllocFunc(size_t size, int alignment)
static void * btAlignedAllocDefault(size_t size, int alignment)
static btFreeFunc * sFreeFunc
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static btAlignedAllocFunc * sAlignedAllocFunc
void() btAlignedFreeFunc(void *memblock)
static btAlignedFreeFunc * sAlignedFreeFunc
static void btAlignedFreeDefault(void *ptr)
static void btFreeDefault(void *ptr)
void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc)
If the developer has already an custom aligned allocator, then btAlignedAllocSetCustomAligned can be ...
void btAlignedAllocSetCustom(btAllocFunc *allocFunc, btFreeFunc *freeFunc)
The developer can let all Bullet memory allocations go through a custom memory allocator, using btAlignedAllocSetCustom.
void() btFreeFunc(void *memblock)
void btAlignedFreeInternal(void *ptr)
void * btAlignedAllocInternal(size_t size, int alignment)
we probably replace this with our own aligned memory allocator so we replace _aligned_malloc and _ali...
T * btAlignPointer(T *unalignedPtr, size_t alignment)
align a pointer to the provided alignment, upwards
static btAllocFunc * sAllocFunc
void *() btAllocFunc(size_t size)
static void * btAllocDefault(size_t size)