delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/28/09:10:58

Message-Id: <m0zCOH2-000S4fC@inti.gov.ar>
Comments: Authenticated sender is <salvador AT natacha DOT inti DOT gov DOT ar>
From: "Salvador Eduardo Tropea (SET)" <salvador AT inti DOT gov DOT ar>
Organization: INTI
To: Endlisnis <s257m AT unb DOT ca>, djgpp AT delorie DOT com
Date: Fri, 28 Aug 1998 10:10:33 +0000
MIME-Version: 1.0
Subject: Re: question to malloc and free
In-reply-to: <35E5EDF2.3DDE5F7D@unb.ca>

Endlisnis <s257m AT unb DOT ca> 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019