示例#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 *dlmalloc(size_t bytes) //maks
{
	void* m = NULL;
	
	do
	{
#ifdef DISABLE_DLMALLOC
		m = malloc(bytes);	
#else
		m = nedmalloc(bytes);		
#endif  
		
		if(!m) 
		{
			//Try allocate again
			
			if(!MemoryAllocationError(bytes))
			{
				//failed				
				break;
			}
		}
		
	} while(!m);
	
	return m;
}
		void * Allocate(size_t Size)
		{
			#ifdef TE_MEMORY_USE_NEDMALLOC
				void * Pointer = nedmalloc(Size);
			#else
				void * Pointer = malloc(Size);
			#endif
			
			#ifdef TE_MEMORY_MANAGEMENT
				if(!Pointer)
					printf("malloc error, size = %i\n", (s32)Size);
			#endif

			++memoryAllocCallsCount;

			return Pointer;
		}
示例#4
0
void MallocStabTest(){
    printf("test\n");
    void ** test=(void**)nedmalloc(1024*1024*16*sizeof(void**));
    for(int i=0;i<(1024*1024*16);i++) test[i]=NULL;
    for(int j=0;j<10000000;j++){
        int testbyte=rand()%((1024*1024*16)-128);

        for(int w=0;w<127;w++){
            if(test[testbyte+w]){
                nedfree(test[testbyte+w]);
                test[testbyte+w]=NULL;
            }
        }

        test[testbyte++]=nedmalloc(10);
        test[testbyte++]=nedmalloc(40);
        test[testbyte++]=nedmalloc(100);

        test[testbyte+2]=nedmalloc(100);
        test[testbyte+1]=nedmalloc(40);
        test[testbyte]=nedmalloc(7);

        testbyte+=3;

        void * mallblocks[7];
        size_t mallsz[7]={10,20,30,40,50,60,70};
        nedindependent_comalloc(7, mallsz, mallblocks);

        test[testbyte++]=mallblocks[0];
        test[testbyte++]=mallblocks[6];
        test[testbyte++]=mallblocks[2];
        test[testbyte++]=mallblocks[5];
        test[testbyte++]=mallblocks[4];
        test[testbyte++]=mallblocks[3];
        test[testbyte++]=mallblocks[1];

    }
    for(int i=0;i<(1024*1024*16);i++) if(test[i]) nedfree(test[i]);
    nedfree(test);
    printf("end\n");
}
示例#5
0
void* CreateMemory( size_t size )
{
	return nedmalloc( size );
}