delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/18/03:12:09

From: "Anthony.Appleyard" <MCLSSAA2 AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: djgpp AT delorie DOT com
Date: Fri, 18 Jul 1997 08:08:40 GMT-1
Subject: Re: mem alloc taking up power of 2
Reply-to: Anthony DOT Appleyard AT umist DOT ac DOT uk
Message-ID: <113AA47926@fs2.mt.umist.ac.uk>

  rs AT redplanet DOT com DOT cy wrote:-
> When I malloc a structure that takes up say 34k, djgpp or dpmi takes 64k, a
> loss of 20k. So if I allocate 32 structures, I lose 640k.

  Nate Eldredge <eldredge AT ap DOT net> replied:-
> AFAIK, no you don't. malloc uses sbrk to get memory from the DPMI server. It
> gets *that* memory in powers of 2 to reduce overhead, but then parcels it
> out to malloc calls as it's needed. So each structure should just be using a
> 34K block, it's just that malloc grabbed some extra which will be given to
> the next request. What makes you think you are losing memory?

No. Unless malloc() has been changed very recently, it (and thus also the C++
operator `new') <do> round up each mallocked block size to (1<<n)-4, i.e. a
(1<<n)-byte block of which 4 bytes are linkage info and the rest available for
allocating. I know, I've read through the source code enough times.

- Raw text -


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