🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #5066

Malloc - what it really does (was: Re: SPUFILE 2.0, C questions)

#5066
From: Rainer Klute
Date: Fri, 20 Oct 1989 08:21
30 lines
2091 bytes
In article <1322@engage.enet.dec.com> wallace@oldtmr.dec.com (Ray Wallace) writes:
>In article <111500042@uxa.cso.uiuc.edu>, glk01126@uxa.cso.uiuc.edu writes...
>>	1) Does Malloc(-1L) not work properly?
>This only returns the size of the largest chunk of free memory. So if you have
>holes in your free memory (non-contiguous) then it will return a number
>smaller than the total of all free memory.

From what I have found out Malloc (-1L) returns the *sum* of the
sizes of *all* free memory chunks. So, what you should not do
without further checking is as follows:

	buffer_size    = Malloc (-1L);
	buffer_address = Malloc (buffer_size);

This will not work as intended because the second Malloc will
result in a pointer to the largest available chunk only, not to
all the free memory, because the latter is not neccessarily
contingous! So the buffer located at 'buffer_address' does not
have a size of 'buffer_size' but of some smaller value. The
real buffer size you can estimate by adding another statement
to those above:

	real_buffer_size = buffer_size - Malloc (-1L);

Disclaimer: I still use TOS 1.0.

  Dipl.-Inform. Rainer Klute      klute@trillian.irb.informatik.uni-dortmund.de
  Univ. Dortmund, IRB             klute@unido.uucp, klute@unido.bitnet
  Postfach 500500         |)|/    ...uunet!mcvax!unido!klute
D-4600 Dortmund 50        |\|\    Tel.: +49 231 755-4663
Technical Details
Message-ID: <1680@laura.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!unido!laura!trillian.irb!klute
References: <1322@engage.enet.dec.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!unido!laura!trillian.irb!klute
From: klute%trillian.irb@unido.uucp (Rainer Klute)
Newsgroups: comp.sys.atari.st
Subject: Malloc - what it really does (was: Re: SPUFILE 2.0, C questions)
Message-ID: <1680@laura.UUCP>
Date: 20 Oct 89 08:21:34 GMT
References: <1322@engage.enet.dec.com>
Sender: news@laura.UUCP
Reply-To: klute@trillian.irb.informatik.uni-dortmund.de (Rainer Klute)
Organization: University of Dortmund, W-Germany
Lines: 30
Work-Address: Postfach 500500, D-4600 Dortmund 50, Tel. +49 231 755-4663
Home-Address: Vinckeplatz 5,   D-4600 Dortmund 1,  Tel. +49 231 128414