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

need a quick allocation tutorial




On Mon, 9 Aug 1999, ccaudle wrote:

> I am in need of some kind soul to give me a quick tutorial on the
> relationship between the library provided allocation function malloc()
> and the rtems region and partition directives.
> 
> For a first basic question, where is the configuration control to make
> sure that memory allocated with malloc isn't using the same memory
> which is being managed by the partition and/or region managers?  Is
> malloc actually implemented as a wrapper on top of the partition
> manager, or are they managing separate memory pools?

malloc is built on the region manager (variable -- partitions are fixed
unit allocation).

> I assume that the whole point of using partitions and regions is that it is 
> faster and/or more deterministic than using malloc?

malloc is implemented using region. malloc calls rtems_region_get_segment.

> The context of this question is that I need a wrapper function to go
> between a device driver library and RTEMS memory management. The
> library is made to be portable, so it just calls out a function for
> memory allocation, which must be supplied by the OS/executive using
> the library, with an argument which can specify requirements of the
> allocation. Most of the requirements are a non-issue for RTEMS, such
> as "virtual=physical," "non-pageable," etc. that would be a concern in
> a multi-process paging OS.

> The flags of concern (i.e. How do I map these into RTEMS calls?) are
> "non-blocking," to indicate that the allocation must not block when
> called (so that it can be called from within an interrupt service
> routine, I assume), and an alignment parameter to specify memory
> alignment. I haven't seen anything in RTEMS memory management which
> lets you specify alignment.

Do you want both blocking and non-blocking allocation requests?

malloc() calls the region manager like this:


  status = rtems_region_get_segment(
    RTEMS_Malloc_Heap,
    size,
    RTEMS_NO_WAIT,
    RTEMS_NO_TIMEOUT,
    &return_this
  );

A non-portable alternate entry to malloc which provided blocking with
optional timeout could easily be constructed.

All it would take is to rename the current malloc as something like
malloc_blocking( size, do_block, timeout ) and fix the arguments to the
get_segment call properly.  Then write a wrapper for it that matched
malloc semantics (do_block = FALSE).

> When I get something working I'll post the information I have.  I'm
> interested in the library for block storage devices, but it includes
> lots of network device drivers, as well as a portable wrapping of the
> BSD network stack. There seem to be a lot of people looking for
> network device drivers, so it may be of interest to several on the
> list.

Sounds like it.

--joel
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985