VxWorks Reference Manual : Wind Foundation Classes
VXWMemPart - memory partition classes
VXWMemPart::VXWMemPart( ) - create a memory partition
VXWMemPart::addToPool( ) - add memory to a memory partition
VXWMemPart::alignedAlloc( ) - allocate aligned memory from partition
VXWMemPart::alloc( ) - allocate a block of memory from partition
VXWMemPart::findMax( ) - find the size of the largest available free block
VXWMemPart::free( ) - free a block of memory in partition
VXWMemPart::info( ) - get partition information
VXWMemPart::options( ) - set the debug options for memory partition
VXWMemPart::realloc( ) - reallocate a block of memory in partition
VXWMemPart::show( ) - show partition blocks and statistics
The VXWMemPart class provides core facilities for managing the allocation of blocks of memory from ranges of memory called memory partitions.
The allocation of memory, using routines such as VXWMemPart::alloc( ), is done with a first-fit algorithm. Adjacent blocks of memory are coalesced when they are freed with VXWMemPart::free( ). There is also a routine provided for allocating memory aligned to a specified boundary from a specific memory partition, VXWMemPart::alignedAlloc( ).
Architectures have various alignment constraints. To provide optimal performance, VXWMemPart::alloc( ) 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 8 12 i960 16 16
vxwMemPartLib.h
VXWMemPart, VXWSem
VXWMemPart::VXWMemPart( ) - create a memory partition
VXWMemPart ( char * pool, unsigned poolSize )
This constructor creates a new memory partition containing a specified memory pool. 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( )).
N/A.
VXWMemPart::addToPool( ) - add memory to a memory partition
STATUS addToPool ( char * pool, unsigned poolSize )
This routine adds memory to its memory partition. The new memory added need not be contiguous with memory previously assigned to the partition.
OK or ERROR.
VXWMemPart::alignedAlloc( ) - allocate aligned memory from partition
void * alignedAlloc ( unsigned nBytes, unsigned alignment )
This routine allocates a buffer of size nBytes from its partition. Additionally, it ensures 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 cannot be allocated.
VXWMemPart::alloc( ) - allocate a block of memory from partition
void * alloc ( unsigned nBytes )
This routine allocates a block of memory from its partition. The size of the block allocated is equal to or greater than nBytes.
A pointer to a block, or NULL if the call fails.
VXWMemPart::findMax( ) - find the size of the largest available free block
int findMax ()
This routine searches for the largest block in the memory partition free list and returns its size.
The size, in bytes, of the largest available block.
VXWMemPart::free( ) - free a block of memory in partition
STATUS free ( char * pBlock )
This routine returns to the partition's free memory list a block of memory previously allocated with VXWMemPart::alloc( ).
OK, or ERROR if the block is invalid.
VXWMemPart::info( ) - get partition information
STATUS info ( MEM_PART_STATS * pPartStats ) const
This routine takes a pointer to a MEM_PART_STATS structure. All the parameters of the structure are filled in with the current partition information.
OK if the structure has valid data, otherwise ERROR.
VXWMemPart::options( ) - set the debug options for memory partition
STATUS options ( unsigned options )
This routine sets the debug options for its memory partition. Two kinds of errors are detected: attempts to allocate more memory than is available, and bad blocks found when memory is freed. In both cases, the error status is returned. There are four error-handling options that can be individually selected:
- MEM_ALLOC_ERROR_LOG_FLAG
- Log a message when there is an error in allocating memory.
- MEM_ALLOC_ERROR_SUSPEND_FLAG
- Suspend the task when there is an error in allocating memory (unless the task was spawned with the VX_UNBREAKABLE option, in which case it cannot be suspended).
- MEM_BLOCK_ERROR_LOG_FLAG
- Log a message when there is an error in freeing memory.
- MEM_BLOCK_ERROR_SUSPEND_FLAG
- Suspend the task when there is an error in freeing memory (unless the task was spawned with the VX_UNBREAKABLE option, in which case it cannot be suspended).
These options are discussed in detail in the library manual entry for memLib.
OK or ERROR.
VXWMemPart::realloc( ) - reallocate a block of memory in partition
void * realloc ( char * pBlock, int nBytes )
This routine changes the size of a specified block of memory and returns a pointer to the new block. The contents that fit inside the new size (or old size if smaller) remain unchanged. The memory alignment of the new block is not guaranteed to be the same as the original block.
If pBlock is NULL, this call is equivalent to VXWMemPart::alloc( ).
A pointer to the new block of memory, or NULL if the call fails.
VXWMemPart::show( ) - show partition blocks and statistics
STATUS show ( int type = 0 ) const
This routine displays statistics about the available and allocated memory in its memory partition. It shows the number of bytes, the number of blocks, and the average block size in both free and allocated memory, and also the maximum block size of free memory. It also shows the number of blocks currently allocated and the average allocated block size.
In addition, if type is 1, the routine displays a list of all the blocks in the free list of the specified partition.
OK or ERROR.