delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/28/12:15:31

From: DougEleveld <deleveld AT dds DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: question to malloc and free
Date: Fri, 28 Aug 1998 18:03:52 +0200
Organization: Rijksuniversiteit Groningen
Lines: 20
Message-ID: <35E6D4E8.275DA73B@dds.nl>
References: <199808271918 DOT PAA16748 AT delorie DOT com> <35E5EDF2 DOT 3DDE5F7D AT unb DOT ca>
NNTP-Posting-Host: client36-126.oprit.rug.nl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Endlisnis wrote:

>     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.

This way the memory actually requested is of a known size and the
allocations can be done _very_ fast.  It's the clasic size/speed
tradeoff.  But remember (I think) that only addressing space from the
4Gig is wasted, not actual memory.  (!Simplified explanation!) Because
if you allocated 1.2k and get 2k, and you never access out of the range
that you are allowed (which you should never do anyway) then the other
0.8k will never get paged in, and it will make very little difference if
0.8k out of the 4gig is wasted, especially since maximum real+virtual
memory is way less than 4gig anyway.

I hope this is right...

Doug Eleveld

- Raw text -


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