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);
73 *((
void **)(ret)-1) = (
void *)(real);
85 real = *((
void **)(ptr)-1);
107#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
109static int allocations_id[10241024];
110static int allocations_bytes[10241024];
111static int mynumallocs = 0;
114int btDumpMemoryLeaks()
118 for (
int i=0;i<mynumallocs;i++)
120 printf(
"Error: leaked memory of allocation #%d (%d bytes)\n", allocations_id[i], allocations_bytes[i]);
121 totalLeak+=allocations_bytes[i];
125 printf(
"Error: memory leaks: %d allocations were not freed and leaked together %d bytes\n",mynumallocs,totalLeak);
132struct btDebugPtrMagic
148 printf(
"Whaat? size==0");
151 static int allocId = 0;
170int sz4prt = 4*
sizeof(
void *);
178 p.cptr-=
sizeof(
void*);
179 *p.vptrptr = (
void*)real;
180 p.cptr-=
sizeof(
void*);
182 p.cptr-=
sizeof(
void*);
185 allocations_id[mynumallocs] = allocId;
186 allocations_bytes[mynumallocs] =
size;
190 ret = (
void *)(real);
193 printf(
"allocation %d at address %x, from %s,line %d, size %d (total allocated = %d)\n",allocId,real, filename,line,
size,
gTotalBytesAlignedAllocs);
196 int* ptr = (
int*)ret;
211 p.cptr-=
sizeof(
void*);
213 p.cptr-=
sizeof(
void*);
215 p.cptr-=
sizeof(
void*);
216 int allocId = *p.iptr;
220 for (
int i=0;i<mynumallocs;i++)
222 if ( allocations_id[i] == allocId)
224 allocations_id[i] = allocations_id[mynumallocs-1];
225 allocations_bytes[i] = allocations_bytes[mynumallocs-1];
236 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)
int gTotalBytesAlignedAllocs
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