void* UserAllocator::malloc(NxU32 size) { #ifdef _DEBUG return mallocDEBUG(size, NULL, 0, "Undefined", NX_MEMORY_PERSISTENT); #endif if(!size) { printf("Warning: trying to allocate 0 bytes\n"); return NULL; } void* ptr = (void*)::malloc(size+8); mTotalNbAllocs++; mNbAllocs++; NxU32* blockStart = (NxU32*)ptr; blockStart[0] = 0xDeadBabe; blockStart[1] = size; mNbAllocatedBytes+=size; if(mNbAllocatedBytes>mHighWaterMark) mHighWaterMark = mNbAllocatedBytes; return ((NxU32*)ptr)+2; #if 0 printf("Obsolete code called!\n"); return NULL; #endif // 0 }
void* UserAllocator::malloc(size_t size, NxMemoryType type) { #ifdef _DEBUG return mallocDEBUG(size, NULL, 0, "Undefined", type); #endif if(size == 0) { printf("Warning: trying to allocate 0 bytes\n"); return NULL; } LockAlloc(); void* ptr = (void*)::malloc(size+2*sizeof(size_t)); mTotalNbAllocs++; mNbAllocs++; size_t* blockStart = (size_t*)ptr; blockStart[0] = g_pointerMarker; blockStart[1] = size; mNbAllocatedBytes+=size; if(mNbAllocatedBytes>mHighWaterMark) mHighWaterMark = mNbAllocatedBytes; UnlockAlloc(); return ((size_t*)ptr)+2; }
void* UserAllocator::malloc(NxU32 size, NxMemoryType type) { // return ::malloc(size); #ifdef _DEBUG return mallocDEBUG(size, NULL, 0, "Undefined", type); #endif if(!size) { printf("Warning: trying to allocate 0 bytes\n"); return NULL; } void* ptr = (void*)::malloc(size+8); mTotalNbAllocs++; mNbAllocs++; NxU32* blockStart = (NxU32*)ptr; blockStart[0] = 0xDeadBabe; blockStart[1] = size; mNbAllocatedBytes+=size; if(mNbAllocatedBytes>mHighWaterMark) mHighWaterMark = mNbAllocatedBytes; return ((NxU32*)ptr)+2; }
void* UserAllocator::malloc(size_t size, NxMemoryType type) { #if defined(_DEBUG) return mallocDEBUG(size, NULL, 0, "Undefined", type); #else if (0 == size) { printf("Warning: trying to allocate 0 bytes\n"); return NULL; } LOCK(); BlockHeader *ptr = reinterpret_cast<BlockHeader *>(::malloc(size + sizeof (BlockHeader))); ptr->sign = BlockHeader::marker; ptr->size = size; ++mTotalNbAllocs; ++mNbAllocs; mNbAllocatedBytes += size; if (mNbAllocatedBytes > mHighWaterMark) mHighWaterMark = mNbAllocatedBytes; UNLOCK(); return &ptr[1]; #endif }