The C++ framework for developing highly scalable, high performance servers on Windows platforms.

CSimpleFixedSizedMemoryAllocator Class Reference
[Win32 Tools Library]

Inheritance diagram for CSimpleFixedSizedMemoryAllocator:
Collaboration diagram for CSimpleFixedSizedMemoryAllocator:

List of all members.


Detailed Description

A class that provides naive fixed sized memory allocation. Note that once the allocator has requested memory from the operating system it never returns it to the operating system, it simply keeps it around until another allocation request can use it. So, if you allocate 1000 1024 byte blocks and then free them all the allocator itself is still holding on to 1024000 bytes of memory. The allocator uses VirtualAlloc() to allocate the memory that it uses, this allows it to provide page aligned memory if requested to do so. It also means that internally it works in terms of multiples of the system's allocation granularity when allocating chunks of memory that it can slice up into blocks to return to the caller. Also, if you specify that you want page alignment and the memory block size that you're using is smaller than an exact page multiple then the difference between the block size and the next multiple of the page size will be 'wasted'.


Public Types

enum  AllocationFlags {
  SizeInBytes = 0x00, SizeInPages = 0x01, SizeBitsMask = 0x0F, NoAlignment = 0x00,
  AlignOnPageSize = 0x10, AlignmentBitsMask = 0xF0
}
 These flags are passed to the constructor of the allocator. SizeInBytes is the default flag and gives an allocator that allocates blocks of the specified size in bytes. Size in pages causes the allocator to treat your block size as a multiple of the system's page size, so by specifying this flag and a block size of 1 you are asking for a block that is the size of the system't memory page. You can OR the AlignOnPageSize flag with the SizeInBytes or SizeInPages flag to tell the allocator that you want each block that is allocated to be aligned on a page boundary. More...

Public Member Functions

 CSimpleFixedSizedMemoryAllocator (size_t blockSize, AllocationFlags allocationFlags=SizeInBytes)
 Create an allocator for memory blocks of the requested size. See AlocationFlags for details of how you can tune the allocators allocation strategy.
 CSimpleFixedSizedMemoryAllocator (const AllocationTuningParameters &tuningParams, size_t blockSize, AllocationFlags allocationFlags=SizeInBytes)
 Create an allocator for memory blocks of the requested size using the supplied allocation tuning parameters. See AlocationFlags for details of how you can tune the allocators allocation strategy.
 CSimpleFixedSizedMemoryAllocator (const CSimpleFixedSizedMemoryAllocator &rhs)
 ~CSimpleFixedSizedMemoryAllocator () override
 Destroys the allocator, note that any blocks that are still allocated when the allocator is destroyed are no longer usable as the underlying memory will be released back to the operating system.
CSimpleFixedSizedMemoryAllocatoroperator= (const CSimpleFixedSizedMemoryAllocator &rhs)
size_t GetAllocationSize () const override
 Returns the size of the allocated blocks.
void * Allocate () override
 Allocate a block of memory.
void Free (void *pMem) override
 Release a block of memory back to the allocator for reuse.

Classes

struct  AllocationTuningParameters


Member Enumeration Documentation

These flags are passed to the constructor of the allocator. SizeInBytes is the default flag and gives an allocator that allocates blocks of the specified size in bytes. Size in pages causes the allocator to treat your block size as a multiple of the system's page size, so by specifying this flag and a block size of 1 you are asking for a block that is the size of the system't memory page. You can OR the AlignOnPageSize flag with the SizeInBytes or SizeInPages flag to tell the allocator that you want each block that is allocated to be aligned on a page boundary.

Enumerator:
SizeInBytes 
SizeInPages 
SizeBitsMask 
NoAlignment 
AlignOnPageSize 
AlignmentBitsMask 


Constructor & Destructor Documentation

CSimpleFixedSizedMemoryAllocator ( size_t  blockSize,
AllocationFlags  allocationFlags = SizeInBytes 
) [explicit]

Create an allocator for memory blocks of the requested size. See AlocationFlags for details of how you can tune the allocators allocation strategy.

CSimpleFixedSizedMemoryAllocator ( const AllocationTuningParameters tuningParams,
size_t  blockSize,
AllocationFlags  allocationFlags = SizeInBytes 
)

Create an allocator for memory blocks of the requested size using the supplied allocation tuning parameters. See AlocationFlags for details of how you can tune the allocators allocation strategy.

~CSimpleFixedSizedMemoryAllocator (  )  [override]

Destroys the allocator, note that any blocks that are still allocated when the allocator is destroyed are no longer usable as the underlying memory will be released back to the operating system.


Member Function Documentation

size_t GetAllocationSize (  )  const [override, virtual]

Returns the size of the allocated blocks.

Implements IAllocateFixedSizedMemory.

void * Allocate (  )  [override, virtual]

Allocate a block of memory.

Implements IAllocateFixedSizedMemory.

void Free ( void *  pMem  )  [override, virtual]

Release a block of memory back to the allocator for reuse.

Implements IAllocateFixedSizedMemory.


Generated on Sun Sep 12 19:11:47 2021 for The Server Framework - v7.4 by doxygen 1.5.3