Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions |
The QMallocPool class allows management of allocations within a designated memory region. More...
#include <QMallocPool>
The QMallocPool class allows management of allocations within a designated memory region.
QMallocPool provides heap management capabilities into a fixed region of memory. Primarily this is useful for managing allocations in a shared memory region, but could be used in other scenarios.
The QMallocPool class provides equivalents for most standard memory management functions, such as malloc, calloc, realloc and free. However, unlike these standard functions which acquire their memory from the system kernel, QMallocPool operators on a region of memory provided to it during construction.
QMallocPool is based on dlmalloc, a public domain malloc implementation written by Doug Lea. dlmalloc is used as the default allocator in many projects, including several versions of Linux libc.
QMallocPool is not thread safe.
Controls the type of pool to be created. In order to manage memory, a small amount of book keeping information is maintained. While this information is not required for reading from the managed pool, it is required for allocations. The PoolType controls where this bookkeeping data is stored.
Constant | Value | Description |
---|---|---|
QMallocPool::Owned | 0 | The bookkeeping data is maintained in the QMallocPool instance. Allocation to the pool is only possible via this instance. |
QMallocPool::NewShared | 1 | The bookkeeping data is maintained in the managed region itself. This allows multiple QMallocPool instances, possibly in separate processes, to allocate from the pool. |
The NewShared PoolType also initializes this bookkeeping data to its default state. Thus, while the bookkeeping data is shared, only one of the sharing instances should use a NewShared type. All other instances should use the Shared pool type.
The malloc pool bookkeeping data contains absolute pointers. As such, if multiple processes intend to allocate into the malloc pool, is is essential that they map the memory region to the same virtual address location.
Constant | Value | Description |
---|---|---|
QMallocPool::Shared | 2 | The bookkeeping data is stored in the managed region, and has previously been initialized by another QMallocPool instance constructed using the NewShared pool type. |
The malloc pool bookkeeping data contains absolute pointers. As such, if multiple processes intend to allocate into the malloc pool, is is essential that they map the memory region to the same virtual address location.
Creates an invalid QMallocPool.
Creates a QMallocPool on the memory region poolBase of length poolLength. The pool will be constructed with the passed type and name. The name is used for diagnostics purposes only.
Destroys the malloc pool.
Allocates memory for an array of nmemb elements of size each and returns a pointer to the allocated memory. The memory is set to zero. Returns 0 if the memory could not be allocated.
Outputs statistical information regarding the state of the malloc pool using qLog().
Frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc() or realloc(). Otherwise, or if free(ptr) has already been called before, undefined behaviour occurs. If ptr is 0, no operation is performed.
Returns true if this is a valid malloc pool. Invalid malloc pools cannot be allocated from.
Allocates size bytes and returns a pointer to the allocated memory. The memory is not cleared. Returns 0 if the memory could not be allocated.
Returns a MemoryStats structure containing information about the memory use of this pool.
Changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged to the minimum of the old and new sizes; newly allocated memory will be uninitialized. If ptr is 0, the call is equivalent to malloc(size); if size is equal to zero, the call is equivalent to free(ptr). Unless ptr is 0, it must have been returned by an earlier call to malloc(), calloc() or realloc(). If the area pointed to was moved, a free(ptr) is done.
Returns the allocated size of mem, assuming mem was previously returned by malloc(), calloc() or realloc().
Copyright © 2009 Nokia | Trademarks | Qt Extended 4.4.3 |