www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/05/07/08:58:20

From: gpk AT physics DOT att DOT com
Date: Fri, 7 May 93 08:04:26 EDT
Original-From: physics!gpk (Greg Kochanski)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: malloc/free broken??

No it's not.  Malloc needs a few extra bytes to store it's private information
(like the size of the allocated block).
Therefore, if you allocate 1000 bytes, you're really using 1004.
If you allocate 500 bytes, you're using 504.

Since 2*504  = 1008 > 1004, you can't expect malloc to recycle the
memory.  If you were to allocate two chunks of size 400, for example,
then it should be able to recycle the memory.

Greg Kochanski  gpk AT physics DOT att DOT com
AT&T Physics Research -- Physics for Fun and Profit

- Raw text -


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