C (88/304)

From:Jack York
Date:11 Aug 2000 at 23:28:37
Subject:Re: memory allocation fcns

Hello Bart

On 07-Aug-00, Bart King wrote:
>> I'm looking for some advice on which memory allocating fcn I
>> should use.
>
> Er, I'm assuming "fcn" stands for "function". This isn't IRC :)

Opps, sorry about that. I thought it was a pretty common
abbreviation. Yes, it does stand for function.
>
>> 1) What is the recommended or most generally used fcn of the
>> three (AllocPooled, AllocVec, AllocMem)?
>
> Depends. AllocMem() is used for antique compatibility with OS 1.x, it
> is rarely required for use under any later revisions.
>
> AllocVec() is the most common form of memory allocation, and the most
> safest.
>
> Pooled memory allocation has a sole use to prevent serious memory
> fragmentation because it allows you to allocate a chunk of RAM and
> manipulate it to smaller chunks. If you allocate lots of small chunks
> of RAM, pooled memory is great, otherwise it has little point, and just
> gets you confused.

By allocating a lot of small chunks do you mean like nodes in a list or
variables that are declared for use in a function (like string buffers)?

>> 2) How does malloc fall into this comparison? Is it used mainly
>> only if portable code is desired or are there other reasons?
>
> malloc() is like an additional "layer" to the memory interface of your
> operating system. All systems have malloc() and without it, memory
> allocation would be very difficult if you don't know your operating
> system at low-level.

The only advantage I can see to malloc is the related realloc. Is
there something similar native to the Amiga that will allow the
resizing of allocated memory?

Jack