Poco

class MemoryPool

File Information

Library: Foundation
Package: Core
Header: Poco/MemoryPool.h

Description

A simple pool for fixed-size memory blocks.

The main purpose of this class is to speed-up memory allocations, as well as to reduce memory fragmentation in situations where the same blocks are allocated all over again, such as in server applications.

All allocated blocks are retained for future use. A limit on the number of blocks can be specified. Blocks can be preallocated.

Member Summary

Member Functions: allocated, available, blockSize, get, release

Constructors

MemoryPool

MemoryPool(
    std::size_t blockSize,
    int preAlloc = 0,
    int maxAlloc = 0
);

Creates a MemoryPool for blocks with the given blockSize. The number of blocks given in preAlloc are preallocated.

Destructor

~MemoryPool

~MemoryPool();

Member Functions

allocated

int allocated() const;

Returns the number of allocated blocks.

available

int available() const;

Returns the number of available blocks in the pool.

blockSize

std::size_t blockSize() const;

Returns the block size.

get

void * get();

Returns a memory block. If there are no more blocks in the pool, a new block will be allocated.

If maxAlloc blocks are already allocated, an OutOfMemoryException is thrown.

release

void release(
    void * ptr
);

Releases a memory block and returns it to the pool.

Securely control IoT edge devices from anywhere   Connect a Device