Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: rs AT redplanet DOT com DOT cy (Rotes Sapiens), djgpp AT delorie DOT com Date: Mon, 21 Jul 1997 16:37:10 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: mem alloc taking up power of 2 Precedence: bulk rs AT redplanet DOT com DOT cy (Rotes Sapiens) wrote: > When I malloc a structure that takes up say 34k, djgpp or dpmi takes > 64k, a loss of 20k. Partially true. > So if I allocate 32 structures, I lose 640k. Is there any way of > stopping malloc from rounding up the memory alloc to the nearest power > of 2 when it takes the memory? I can't see anything in the faq about > it. You allready got replies but I want to let it clear: 1) As Anthony said is true that for 34Kb you'll allocate 64Kb so what you say is true, but not 100% 2) Another added something about pages that complets the idea but was a little cryptic. The thing is like this: you really allocate 64Kb but that doesn't mean you are really wasting the 20Kb. That's because you'll never touch this memory and hence the Virtual Memory manager of the DPMI server will see that and will remap it to be used paging to the disk a portion of memory that you'll never use and hence reusing part of your 20Kb memory. In fact you are loosing 2Kb. That's not true if you: 1) Use all the virtual memory. 2) You disable the virtual memory. Under these cases you loose 20Kb. Now as other said before the djgpp's malloc is really fast and that's what you pay in exchange. The drawbacks are even greater than this (Anthony and me designed a modified malloc to work-around some limitations). If you will need to allocate 32 structures of 34Kb you'll loose memory. Try to make it 32Kb-4 and you won't waste memory. For example split your struct. Or create your own memory manager (Quake makes that). SET ------------------------------------ 0 -------------------------------- Visit my home page: http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013