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 39 #if defined (BT_HAS_ALIGNED_ALLOCATOR) 43 return _aligned_malloc(size, (
size_t)alignment);
50 #elif defined(__CELLOS_LV2__) 55 return memalign(alignment,
size);
72 real = (
char *)
sAllocFunc(size +
sizeof(
void *) + (alignment-1));
75 *((
void **)(ret)-1) = (
void *)(real);
87 real = *((
void **)(ptr)-1);
109 #ifdef BT_DEBUG_MEMORY_ALLOCATIONS 111 static int allocations_id[10241024];
112 static int allocations_bytes[10241024];
113 static int mynumallocs = 0;
116 int btDumpMemoryLeaks()
120 for (
int i=0;i<mynumallocs;i++)
122 printf(
"Error: leaked memory of allocation #%d (%d bytes)\n", allocations_id[i], allocations_bytes[i]);
123 totalLeak+=allocations_bytes[i];
127 printf(
"Error: memory leaks: %d allocations were not freed and leaked together %d bytes\n",mynumallocs,totalLeak);
134 struct btDebugPtrMagic
150 printf(
"Whaat? size==0");
153 static int allocId = 0;
168 gTotalBytesAlignedAllocs +=
size;
172 int sz4prt = 4*
sizeof(
void *);
180 p.cptr-=
sizeof(
void*);
181 *p.vptrptr = (
void*)real;
182 p.cptr-=
sizeof(
void*);
184 p.cptr-=
sizeof(
void*);
187 allocations_id[mynumallocs] = allocId;
188 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];
235 gTotalBytesAlignedAllocs -=
size;
237 int diff = gNumAlignedAllocs-gNumAlignedFree;
238 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);
247 #else //BT_DEBUG_MEMORY_ALLOCATIONS 268 #endif //BT_DEBUG_MEMORY_ALLOCATIONS static void * btAlignedAllocDefault(size_t size, int alignment)
static btFreeFunc * sFreeFunc
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static btAlignedAllocFunc * sAlignedAllocFunc
void( btFreeFunc)(void *memblock)
void *( btAlignedAllocFunc)(size_t size, int alignment)
static btAlignedFreeFunc * sAlignedFreeFunc
void( btAlignedFreeFunc)(void *memblock)
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 *( btAllocFunc)(size_t size)
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
static void * btAllocDefault(size_t size)