예제 #1
0
static void run(size_t maxsize, size_t records, size_t loops)
{
	int n,m;
	static void *mem[RECORDS];
	for(m=0; m<loops; m++)
	{
		for(n=0; n<records-1; n++)
		{
			static int reallocflip;
			int dorealloc=(reallocflip=!reallocflip);
			size_t size=rand() & (maxsize-1);
			if(!mem[n])
				mem[n]=nedmalloc(size);
			else if(n>0 && dorealloc)
				mem[n-1]=nedrealloc(mem[n-1], size);
			else if(n>1)
			{
				nedfree(mem[n-2]);
				mem[n-2]=0;
			}
		}
	}
	for(n=0; n<records; n++)
	{
		if(mem[n])
		{
			nedfree(mem[n]);
			mem[n]=0;
		}
	}
}
예제 #2
0
void* dlrealloc(void* m, size_t bytes) //maks
{
	void* newMem = NULL;

	if(bytes <= 0 && m)
	{
		dlfree(m);
		return 0;
	}
	
	do
	{
#ifdef DISABLE_DLMALLOC
		newMem = realloc(m, bytes);
#else
		newMem = nedrealloc(m, bytes);		
#endif   
		
		if(!newMem && bytes > 0) 
		{
			//Try allocate again
			if(!MemoryAllocationError(bytes))
			{
				//failed
				break;
			}
		}
		
	} while(!newMem);

  return newMem;
}
예제 #3
0
		void * ReAllocate(void * Pointer, size_t Size)
		{
			#ifdef TE_MEMORY_USE_NEDMALLOC
				void * NewPointer = nedrealloc(Pointer, Size);
			#else
				void * NewPointer = realloc(Pointer, Size);
			#endif
			
			#ifdef TE_MEMORY_MANAGEMENT
				if(!NewPointer)
					printf("realloc error, size = %i\n", (s32)Size);
			#endif

			++memoryReallocCallsCount;
			
			return NewPointer;
		}