www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/13/19:56:26

To: djgpp AT delorie DOT com
Subject: Re: how to free memory?
Message-ID: <19970113.162550.4975.7.chambersb@juno.com>
References: <Pine DOT LNX DOT 3 DOT 95 DOT 970113173110 DOT 29760A-100000 AT ajax DOT umcs DOT lublin DOT pl>
From: chambersb AT juno DOT com (Benjamin D Chambers)
Date: Mon, 13 Jan 1997 19:26:49 EST

[censored].
That [censored] [censored] Windoze just rebooted, when I was almost done
typing my reply. :(

On Mon, 13 Jan 1997 17:41:19 +0100 (MET) Grzegorz Ludorowski
<pajonk AT ajax DOT umcs DOT lublin DOT pl> writes:
>> 
>Ok. So I have to set some variables everytime I allocate or deallocate
>memory. It's clear. Besides, I don't know why have I to do that on my 
>own?
>IMHO it should be done by djgpp... but ok - I can do it. (what will
>happened if I could not ?) But one thing sounds VERY strange to me:
>I can't allocate .. say 9MB of ram because when I will do that, djgpp 
>will
>allocate 16MB.. am I right? It rounds up everything to the next power 
>of
>2? So what will happened if I'd like to allocate 10x 300kb? It will 
>change
>to 10x512kb of allocated memory? 
>If this is true [..censored..]. 
>				LUDO.
>PS. Or maybe I'm too lame to use djgpp :))
It's not quite _that_ bad, and you aren't too lame :)

When you allocate that 9 megs, malloc really points to a 16 meg area. 
However, when you malloc that 3000k (as in, p=malloc(10*300*1024)) malloc
takes that from the remaining 6 megs that have been allocated.  Since the
memory isn't actually accessed until you use it (unless you use calloc,
which zeroes out the memory) it doesn't hurt anything to have it in the
memory map - and speeds things up when you want that next allocation.
I didn't make any mistakes above, did I, guys?

...Chambers

- Raw text -


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