Newsgroups: comp.sys.amiga.programmer
Path: utzoo!utgpu!watserv1!maytag!csg.uwaterloo.ca!giguere
From: giguere@csg.uwaterloo.ca (Eric Giguere)
Subject: Re: Two questions about memory allocation
Message-ID: <1991Jan9.214819.3833@maytag.waterloo.edu>
Sender: daemon@maytag.waterloo.edu (Admin)
Organization: University of Waterloo
References: <8135@ucdavis.ucdavis.edu>
Date: Wed, 9 Jan 91 21:48:19 GMT
Lines: 20

Routines like "malloc" and "free" are not Amiga-specific routines.  These
routines are provided by the C library you're linking to.  They eventually
call the Amiga routines AllocMem and FreeMem to get and free the memory,
but also keep track of the memory your program is using (something which
AllocMem/FreeMem won't do) and make sure all the memory is returned to
the system when your program exits.

If you're concerned about efficiency, you should use the low-level AllocMem
call.  However, you'll have to make sure that your program returns every
single piece of memory it allocates!  (AllocMem is also useful if you need
to explicitly get CHIP memory.)

If you're allocating and deallocating a lot of small items repeatedly,
it might be worth it to allocate one large chunk of memory at the beginning
of your program and do the assignments within that chunk yourself.  Also,
Intuition has an AllocRemember function to help with that kind of activity.

--
Eric Giguere                                       giguere@csg.UWaterloo.CA
           Quoth the raven: "Eat my shorts!" --- Poe & Groening
