PageAllocator Class Reference

#include <Pt/PageAllocator.h>

Page based allocator. More...

Inherits Allocator, and NonCopyable.

Public Member Functions

 PageAllocator (std::size_t pageSize=MinChunkSize)
 Construct with minimum page size.
 
 ~PageAllocator ()
 Destructor.
 
void clear ()
 Releases all memory.
 
void * allocate (std::size_t size)
 Allocates size bytes of memory.
 
void deallocate (void *p, std::size_t size)
 Deallocates memory of size bytes.
 

Detailed Description

The PageAllocator is useful, when chunks of memory have to be allocated, that can be released simultaneously. This allows the PageAllocator to allocate memory consecutively on pages and simply release all pages together at the end. Therefore, deallocate() will not do anything, but memory will only eventually be released, when clear() is called or the PageAllocator is destructed. The next example illustrates this:

void useAllocator(Pt::Allocator& a)
{
for(std::size_t n = 1; n < 16; ++n)
{
void* p = a.allocate(n);
...
// won't do anything if it's a PoolAllocator
a.deallocate(p, n);
}
}
useAllocator(allocator);
// release all allocated memory
allocator.clear();
void clear()
Releases all memory.
virtual void * allocate(std::size_t size)
Allocates size bytes of memory.
Definition: Allocator.h:96
Allocator interface.
Definition: Allocator.h:82
Page based allocator.
Definition: PageAllocator.h:77
virtual void deallocate(void *p, std::size_t)
Deallocates memory of size bytes.
Definition: Allocator.h:103