Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: djgpp AT delorie DOT com Date: Wed, 29 Oct 1997 16:19:37 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: malloc() Precedence: bulk From: "John Machin" Subject: malloc() I did a test with the Doug Lea malloc propossed by John Machin. I found that dlmalloc uses 2^n chunks BUT joins various of different size to satisfy a malloc request. In this way avoids some memory wastage. My test was the following: My program uses 10000 pseudo-aleatory numbers, the numbers indicates if we will delete or allocate a block, the index in a 1024 elements array and the size of the block (0-128Kb). The result was that dlmalloc wastes less memory: BSD malloc (DJGPP) used 67305472 bytes for the heap. dlmalloc used 51052544 bytes, that's 24% less. But the difference is speed is huge: BSD malloc/free 0.22 seconds. dlmalloc: 1.54 seconds 7 times more!!! I don't think is a good idea to replace the current one. Perhaps is possible to allow the option to use dlmalloc or put it in the FAQ. Here is the program used (you'll need more than 64Mb free to run it ;-). #include #include #include #include #include #include int coreleft() { _go32_dpmi_meminfo info; _go32_dpmi_get_free_memory_information(&info); return info.available_memory; } char *array[1024]; int main(int argc, char *argv[]) { char *s; int ori=coreleft(); int i,index,val,del,size; clock_t t1,t2; srandom(0); memset(array,0,1024*4); t1=clock(); for (i=0; i<10000; i++) { val=random(); index=val & 0x3FF; del=val & 0x400; if (del) { if (array[index]!=0) { free(array[index]); array[index]=0; } else del=0; } if (!del) { size=(val>>11) & 0x1FFFF; if (array[index]!=0) free(array[index]); array[index]=malloc(size); } } t2=clock(); printf("Memory left after it %d, used %d\n",coreleft(),ori-coreleft()); printf("Elapsed time: %f\n",(float)(t2-t1)/CLOCKS_PER_SEC); return 0; } SET ------------------------------------ 0 -------------------------------- Visit my home page: http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-sot AT usa DOT net - ICQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013