VxWorks Reference Manual : Wind Foundation Classes

VXWMemPart

NAME

VXWMemPart - memory partition classes

METHODS

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

DESCRIPTION

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( ).

CAVEATS

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

INCLUDE FILES

vxwMemPartLib.h

SEE ALSO

VXWMemPart, VXWSem


Wind Foundation Classes : Methods

VXWMemPart::VXWMemPart( )

NAME

VXWMemPart::VXWMemPart( ) - create a memory partition

SYNOPSIS

VXWMemPart
    (
    char *   pool,
    unsigned poolSize
    )

DESCRIPTION

This constructor creates a new memory partition containing a specified memory pool. Partitions can be created to manage any number of separate memory pools.

NOTE

The descriptor for the new partition is allocated out of the system memory partition (i.e., with malloc( )).

RETURNS

N/A.

SEE ALSO

VXWMemPart


Wind Foundation Classes : Methods

VXWMemPart::addToPool( )

NAME

VXWMemPart::addToPool( ) - add memory to a memory partition

SYNOPSIS

STATUS addToPool
    (
    char *   pool,
    unsigned poolSize
    )

DESCRIPTION

This routine adds memory to its memory partition. The new memory added need not be contiguous with memory previously assigned to the partition.

RETURNS

OK or ERROR.

SEE ALSO

VXWMemPart


Wind Foundation Classes : Methods

VXWMemPart::alignedAlloc( )

NAME

VXWMemPart::alignedAlloc( ) - allocate aligned memory from partition

SYNOPSIS

void * alignedAlloc
    (
    unsigned nBytes,
    unsigned alignment
    )

DESCRIPTION

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.

RETURNS

A pointer to the newly allocated block, or NULL if the buffer cannot be allocated.

SEE ALSO

VXWMemPart


Wind Foundation Classes : Methods

VXWMemPart::alloc( )

NAME

VXWMemPart::alloc( ) - allocate a block of memory from partition

SYNOPSIS

void * alloc
    (
    unsigned nBytes
    )

DESCRIPTION

This routine allocates a block of memory from its partition. The size of the block allocated is equal to or greater than nBytes.

RETURNS

A pointer to a block, or NULL if the call fails.

SEE ALSO

VXWMemPart::free( )


Wind Foundation Classes : Methods

VXWMemPart::findMax( )

NAME

VXWMemPart::findMax( ) - find the size of the largest available free block

SYNOPSIS

    int findMax ()

DESCRIPTION

This routine searches for the largest block in the memory partition free list and returns its size.

RETURNS

The size, in bytes, of the largest available block.

SEE ALSO

VXWMemPart


Wind Foundation Classes : Methods

VXWMemPart::free( )

NAME

VXWMemPart::free( ) - free a block of memory in partition

SYNOPSIS

STATUS free
    (
    char * pBlock
    )

DESCRIPTION

This routine returns to the partition's free memory list a block of memory previously allocated with VXWMemPart::alloc( ).

RETURNS

OK, or ERROR if the block is invalid.

SEE ALSO

VXWMemPart::alloc( )


Wind Foundation Classes : Methods

VXWMemPart::info( )

NAME

VXWMemPart::info( ) - get partition information

SYNOPSIS

STATUS info
    (
    MEM_PART_STATS * pPartStats
    ) const

DESCRIPTION

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.

RETURNS

OK if the structure has valid data, otherwise ERROR.

SEE ALSO

VXWMemPart::show( )


Wind Foundation Classes : Methods

VXWMemPart::options( )

NAME

VXWMemPart::options( ) - set the debug options for memory partition

SYNOPSIS

STATUS options
    (
    unsigned options
    )

DESCRIPTION

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.

RETURNS

OK or ERROR.

SEE ALSO

VXWMemPart


Wind Foundation Classes : Methods

VXWMemPart::realloc( )

NAME

VXWMemPart::realloc( ) - reallocate a block of memory in partition

SYNOPSIS

void * realloc
    (
    char * pBlock,
    int    nBytes
    )

DESCRIPTION

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( ).

RETURNS

A pointer to the new block of memory, or NULL if the call fails.

SEE ALSO

VXWMemPart


Wind Foundation Classes : Methods

VXWMemPart::show( )

NAME

VXWMemPart::show( ) - show partition blocks and statistics

SYNOPSIS

STATUS show
    (
    int type = 0
    ) const

DESCRIPTION

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.

RETURNS

OK or ERROR.

SEE ALSO

VXWMemPart