void*   btAlignedAllocInternal  (size_t size, int alignment,int line,char* filename)
{
 void *ret;
 char *real;

 gTotalBytesAlignedAllocs += size;
 gNumAlignedAllocs++;

 
 real = (char *)sAllocFunc(size + 2*sizeof(void *) + (alignment-1));
 if (real) {
   ret = (void*) btAlignPointer(real + 2*sizeof(void *), alignment);
   *((void **)(ret)-1) = (void *)(real);
       *((int*)(ret)-2) = size;

 } else {
   ret = (void *)(real);//??
 }

 printf("allocation#%d at address %x, from %s,line %d, size %d\n",gNumAlignedAllocs,real, filename,line,size);

 int* ptr = (int*)ret;
 *ptr = 12;
 return (ret);
}
Exemplo n.º 2
0
void*   btAlignedAllocInternal  (size_t size, int alignment,int line,char* filename)
{
	if (size==0)
	{
		printf("Whaat? size==0");
		return 0;
	}
	static int allocId = 0;
	
 void *ret;
 char *real;

// to find some particular memory leak, you could do something like this:
//	if (allocId==172)
//	{
//		printf("catch me!\n");
//	}
//	if (size>1024*1024)
//	{
//		printf("big alloc!%d\n", size);
//	}

 gTotalBytesAlignedAllocs += size;
 gNumAlignedAllocs++;

 
int sz4prt = 4*sizeof(void *);
	
 real = (char *)sAllocFunc(size + sz4prt + (alignment-1));
 if (real) {
	 
   ret = (void*) btAlignPointer(real + sz4prt, alignment);
	 btDebugPtrMagic p;
	 p.vptr = ret;
	 p.cptr-=sizeof(void*);
	 *p.vptrptr = (void*)real;
	 p.cptr-=sizeof(void*);
	 *p.iptr = size;
	 p.cptr-=sizeof(void*);
	 *p.iptr = allocId;
	 
	 allocations_id[mynumallocs] = allocId;
	 allocations_bytes[mynumallocs] = size;
	 mynumallocs++;

 } else {
   ret = (void *)(real);//??
 }

 printf("allocation %d at address %x, from %s,line %d, size %d (total allocated = %d)\n",allocId,real, filename,line,size,gTotalBytesAlignedAllocs);
	allocId++;
	
 int* ptr = (int*)ret;
 *ptr = 12;
 return (ret);
}
Exemplo n.º 3
0
static inline void *btAlignedAllocDefault(size_t size, int alignment)
{
  void *ret;
  char *real;
  real = (char *)sAllocFunc(size + sizeof(void *) + (alignment-1));
  if (real) {
	ret = btAlignPointer(real + sizeof(void *),alignment);
    *((void **)(ret)-1) = (void *)(real);
  } else {
    ret = (void *)(real);
  }
  return (ret);
}
Exemplo n.º 4
0
static inline void* btAlignedAllocDefault(size_t size, int32_t alignment)
{
    void* ret;
    char* real;
    unsigned long offset;

    real = (char*)sAllocFunc(size + sizeof(void*) + (alignment - 1));
    if (real) {
        // -- GODOT start --
        // Synced with Bullet 2.88 to fix GH-27926
        //offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1);
        //ret = (void*)((real + sizeof(void*)) + offset);
        ret = btAlignPointer(real + sizeof(void *), alignment);
        // -- GODOT end --
        *((void**)(ret)-1) = (void*)(real);
    }
    else {
        ret = (void*)(real);
    }
    return (ret);
}