[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

need a quick allocation tutorial





On Mon, 9 Aug 1999, ccaudle wrote:

> >===== Original Message From <joel at OARcorp.com> =====
> >malloc is built on the region manager (variable -- partitions are fixed
> >unit allocation).
> 
> OK, that makes sense.  Where is the malloc heap set up?
> I'm assuming that if you use the region (or partition) manager directly, you 
> need to make sure that the memory range used isn't already in use by the 
> region created for malloc.

I just added this to the growing FAQ... see what you think..

When is malloc initialized?
---------------------------

During BSP initialization, the `bsp_libc_init' routine is called.  This
routine initializes the heap as well as the RTEMS system call layer
(open, read, write, etc.) and the RTEMS reentrancy support for the
Cygnus newlib Standard C Library.

The `bsp_libc_init' routine is passed the size and starting address of
the memory area to be used for the program heap as well as the amount
of memory to ask `sbrk' for when the heap is exhausted.  For most BSPs,
all memory available is placed in the program heap thus it can not be
extended dynamically by calls to `sbrk'.

> Or should I not bother, and just always use malloc?

Unless you have want a special purpose memory pool, I would stick to
malloc.

> Any ideas on the alignment flag?  I'm not sure I will actually have to 
> implement this, since whether or not the flag is actively used will probably 
> depend on which libraries I link in.

The region used for the program heap is initialized such that the
alignment requirements for the strictest C object are met.  This is port
(NOT BSP) dependent but usually means that items are 4 or 8 byte aligned.

I would not fool with it until I found a reason to. :)

> I will probably try not implementing it first, but in case it is needed, does 
> RTEMS have a way to specify alignment for allocated memory blocks?

Each region has its own memory alignment for items allocated from that
region. You would have to go through the C library to get the ability to
specify it on a per block basis.

--joel