VxWorks Reference Manual : Libraries
memPartLib - core memory partition manager
memPartCreate( ) - create a memory partition
memPartAddToPool( ) - add memory to a memory partition
memPartAlignedAlloc( ) - allocate aligned memory from a partition
memPartAlloc( ) - allocate a block of memory from a partition
memPartFree( ) - free a block of memory in a partition
memAddToPool( ) - add memory to the system memory partition
malloc( ) - allocate a block of memory from the system memory partition (ANSI)
free( ) - free a block of memory (ANSI)
This library provides core facilities for managing the allocation of blocks of memory from ranges of memory called memory partitions. The library was designed to provide a compact implementation; full-featured functionality is available with memLib, which provides enhanced memory management features built as an extension of memPartLib. (For more information about enhanced memory partition management options, see the manual entry for memLib.) This library consists of two sets of routines. The first set, memPart...( ), comprises a general facility for the creation and management of memory partitions, and for the allocation and deallocation of blocks from those partitions. The second set provides a traditional ANSI-compatible malloc( )/free( ) interface to the system memory partition.
The system memory partition is created when the kernel is initialized by kernelInit( ), which is called by the root task, usrRoot( ), in usrConfig.c. The ID of the system memory partition is stored in the global variable memSysPartId; its declaration is included in memLib.h.
The allocation of memory, using malloc( ) in the typical case and memPartAlloc( ) for a specific memory partition, is done with a first-fit algorithm. Adjacent blocks of memory are coalesced when they are freed with memPartFree( ) and free( ). There is also a routine provided for allocating memory aligned to a specified boundary from a specific memory partition, memPartAlignedAlloc( ).
Architectures have various alignment constraints. To provide optimal performance, malloc( ) returns a pointer to a buffer having the appropriate alignment for the architecture in use. The portion of the allocated buffer reserved for system bookkeeping, known as the overhead, may vary depending on the architecture.
Architecture Boundary Overhead 68K 4 8 SPARC 8 12 MIPS 16 12 i960 16 16
memLib.h, stdlib.h
memPartCreate( ) - create a memory partition
PART_ID memPartCreate ( char * pPool, /* pointer to memory area */ unsigned poolSize /* size in bytes */ )
This routine creates a new memory partition containing a specified memory pool. It returns a partition ID, which can then be passed to other routines to manage the partition (i.e., to allocate and free memory blocks in the partition). Partitions can be created to manage any number of separate memory pools.
The descriptor for the new partition is allocated out of the system memory partition (i.e., with malloc( )).
The partition ID, or NULL if there is insufficient memory in the system memory partition for a new partition descriptor.
memPartAddToPool( ) - add memory to a memory partition
STATUS memPartAddToPool ( PART_ID partId, /* partition to initialize */ char * pPool, /* pointer to memory block */ unsigned poolSize /* block size in bytes */ )
This routine adds memory to a specified memory partition already created with memPartCreate( ). The memory added need not be contiguous with memory previously assigned to the partition.
OK or ERROR.
S_smObjLib_NOT_INITIALIZED, S_memLib_INVALID_NBYTES
memPartLib, smMemLib, memPartCreate( )
memPartAlignedAlloc( ) - allocate aligned memory from a partition
void *memPartAlignedAlloc ( PART_ID partId, /* memory partition to allocate from */ unsigned nBytes, /* number of bytes to allocate */ unsigned alignment /* boundary to align to */ )
This routine allocates a buffer of size nBytes from a specified partition. Additionally, it insures that the allocated buffer begins on a memory address evenly divisible by alignment. The alignment parameter must be a power of 2.
A pointer to the newly allocated block, or NULL if the buffer could not be allocated.
memPartAlloc( ) - allocate a block of memory from a partition
void *memPartAlloc ( PART_ID partId, /* memory partition to allocate from */ unsigned nBytes /* number of bytes to allocate */ )
This routine allocates a block of memory from a specified partition. The size of the block will be equal to or greater than nBytes. The partition must already be created with memPartCreate( ).
A pointer to a block, or NULL if the call fails.
S_smObjLib_NOT_INITIALIZED
memPartLib, smMemLib, memPartCreate( )
memPartFree( ) - free a block of memory in a partition
STATUS memPartFree ( PART_ID partId, /* memory partition to add block to */ char * pBlock /* pointer to block of memory to free */ )
This routine returns to a partition's free memory list a block of memory previously allocated with memPartAlloc( ).
OK, or ERROR if the block is invalid.
S_smObjLib_NOT_INITIALIZED
memPartLib, smMemLib, memPartAlloc( )
memAddToPool( ) - add memory to the system memory partition
void memAddToPool ( char * pPool, /* pointer to memory block */ unsigned poolSize /* block size in bytes */ )
This routine adds memory to the system memory partition, after the initial allocation of memory to the system memory partition.
N/A
memPartLib, memPartAddToPool( )
malloc( ) - allocate a block of memory from the system memory partition (ANSI)
void *malloc ( size_t nBytes /* number of bytes to allocate */ )
This routine allocates a block of memory from the free list. The size of the block will be equal to or greater than nBytes.
A pointer to the allocated block of memory, or a null pointer if there is an error.
memPartLib, American National Standard for Information Systems - Programming Language - C, ANSI X3.159-1989: General Utilities (stdlib.h)
free( ) - free a block of memory (ANSI)
void free ( void * ptr /* pointer to block of memory to free */ )
This routine returns to the free memory pool a block of memory previously allocated with malloc( ) or calloc( ).
N/A
memPartLib, malloc( ), calloc( ), American National Standard for Information Systems - Programming Language - C, ANSI X3.159-1989: General Utilities (stdlib.h)