Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: Endlisnis , djgpp AT delorie DOT com Date: Fri, 28 Aug 1998 10:10:33 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: question to malloc and free In-reply-to: <35E5EDF2.3DDE5F7D@unb.ca> Precedence: bulk Endlisnis wrote: > DJ Delorie wrote: > > > The actual block in memory consists of a few extra words just before > > what you get your hand on. That extra bit contains the size of the > > block, and maybe some other information if you're using a malloc > > debugger. > > Why not download the source and see for yourself? > > I've read that the size of the block allocated by malloc/new is always > a power of 2, and rounded up to one if it isn't (after adding it's few > words). Why does it do this? This seems (to me) like it would waste about > 1/2 the RAM allocated. First: DJ did a new malloc included in v2.02 to solve it. Now: You waste some *virtual memory* not physical so normally doesn't affect. The reason malloc works in this way is because is *fast*, the blocks are clasified by size, only 32 sizes and to satisfy a malloc request you just need to check if one block is available (in linked list of blocks of this size) or create a new one, no "heap walks" are needed (like in Borland's malloc). Of course there are better solutions like the one used by DJ in the last malloc. SET ------------------------------------ 0 -------------------------------- Visit my home page: http://set-soft.home.ml.org/ or http://www.geocities.com/SiliconValley/Vista/6552/ Salvador Eduardo Tropea (SET). (Electronics Engineer) Alternative e-mail: set-soft AT usa DOT net set AT computer DOT org ICQ: 2951574 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013