18 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS
19 int gNumAlignedAllocs = 0;
20 int gNumAlignedFree = 0;
21 int gTotalBytesAlignedAllocs = 0;
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);
70 *((
void **)(
ret)-1) = (
void *)(
real);
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;
190 printf(
"allocation %d at address %x, from %s,line %d, size %d (total allocated = %d)\n", allocId,
real, filename, line,
size, gTotalBytesAlignedAllocs);
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);
void BLI_kdtree_nd_() free(KDTree *tree)
static btAlignedAllocFunc * sAlignedAllocFunc
static void btAlignedFreeDefault(void *ptr)
static void * btAllocDefault(size_t size)
static btAllocFunc * sAllocFunc
void btAlignedAllocSetCustomAligned(btAlignedAllocFunc *allocFunc, btAlignedFreeFunc *freeFunc)
If the developer has already an custom aligned allocator, then btAlignedAllocSetCustomAligned can be ...
static void * btAlignedAllocDefault(size_t size, int alignment)
static void btFreeDefault(void *ptr)
static btFreeFunc * sFreeFunc
void * btAlignedAllocInternal(size_t size, int alignment)
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
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt=1)