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

CBufferAllocator Class Reference

Inheritance diagram for CBufferAllocator:
Collaboration diagram for CBufferAllocator:

List of all members.

Public Types

enum  AllocationFlags {
  SizeInBytes = 0x00, SizeInPages = 0x01, RoundUpToPageSize = 0x02, UseByteAllocator = 0x00,
  UsePageAllocator = 0x10, SizeBitsMask = 0x0F, AllocatorBitsMask = 0xF0
}
 These flags are passed to the constructor of the allocator. SizeInBytes is the default flag and gives a buffer with a bufferSize in bytes and uses C++ new to allocate the memory; this is consistent with previous versions of the library. If you specify the UsePageAllocator flag then the buffers are allocated with VirtualAlloc() and are page aligned. If you specify RoundUpToPageSize your buffer size is taken as a base and the size of the buffer's housekeeping data is added on and the total size is then rounded up to the next multiple of the system's page size. If you specify SizeInPages then the bufferSize is multiplied by the system's page size to give the size of the memory that is allocated, the actual usable buffer size in such an instance is the memory allocated less the buffer's housekeeping data. More...
typedef unsigned long BufferCount
typedef ULONG_PTR CallbackUserData
typedef
IBuffer::BufferSize 
BufferSize

Public Member Functions

 CBufferAllocator (BufferSize bufferSize, BufferCount maxFreeBuffers, bool log=true)
 CBufferAllocator (BufferSize bufferSize, BufferCount maxFreeBuffers, AllocationFlags flags, bool log=true)
 CBufferAllocator (const CBufferAllocator &rhs)
 ~CBufferAllocator ()
CBufferAllocatoroperator= (const CBufferAllocator &rhs)
BufferCount EnlargePool (BufferCount buffersToAdd)
 Add buffersToAdd buffers to the pool.
JetByteTools::Core::IIndexedOpaqueUserData::UserDataIndex RequestUserDataSlot (const JetByteTools::Core::_tstring &name) override
 Request a named user data slot and get an index to use in calls to methods on IIndexedOpaqueUserData.
JetByteTools::Core::IIndexedOpaqueUserData::UserDataIndex LockUserDataSlots () override
 Prevent more user data slots from being allocated. Returns the number of user data slots that have been allocated.
CSmartBuffer Allocate () override
 Allocate an instance of IBuffer, remember to call Release() on it when you're done with it.
CSmartBuffer AllocateCustomSizedBuffer (BufferSize bufferSize) override
CSmartBuffer AllocateCustomSizedBuffer (BufferSize bufferSize) override=0
 Creates a buffer that is a specific size rather than the size that the allocator usually creates. These buffers are currently NOT pooled and are deleted when the last reference is released.
void AllocateBuffers (size_t numBuffers, CBufferChain &buffers) override
void AllocateBuffersForBytes (size_t numBytes, CBufferChain &buffers) override
BufferSize GetBufferSize () const override
 If an allocator is supplied or if any AllocationFlags other than SizeInBytes is specified then the actual usable size of the buffer will not be known until the user data slots of the allocator have been locked. This happens automatically when the first buffer is allocated or can be done at any time prior to that by calling LockUserDataSlots() explicitly. If GetBufferSize() before the usable size of the buffer is known then an exception is thrown.
bool Flush () override
 Flushes the allocator. Use with care as this forces active buffers to be released and destroyed! Generally only called as part of process cleanup and even then only to aid in buffer leak tracking.
BufferCount GetNumActive () const
BufferCount GetNumPooled () const
void IterateActiveList (CallbackUserData userData, const BufferIterationCallback &callback)

Static Public Attributes

static const BufferCount NoPooledBuffers = std::numeric_limits<CBufferAllocator::BufferCount>::max()
 Pass this value as maxFreeBuffers to constructors to create an allocator that doesn't pool buffers at all.
static const BufferCount MaxBufferCount = std::numeric_limits<CBufferAllocator::BufferCount>::max() - 1
static const
JetByteTools::Core::IIndexedOpaqueUserData::UserDataIndex 
DefaultBufferChainIndex = 0
static const
JetByteTools::Core::IIndexedOpaqueUserData::UserDataIndex 
NumberOfDefaultUserDataSlots = 1

Static Protected Member Functions

static void AllocateDefaultUserDataIndices (JetByteTools::Core::IProvideUserData &dataProvider)


Member Typedef Documentation

typedef unsigned long BufferCount [inherited]

typedef ULONG_PTR CallbackUserData [inherited]

typedef IBuffer::BufferSize BufferSize [inherited]


Member Enumeration Documentation

enum AllocationFlags [inherited]

These flags are passed to the constructor of the allocator. SizeInBytes is the default flag and gives a buffer with a bufferSize in bytes and uses C++ new to allocate the memory; this is consistent with previous versions of the library. If you specify the UsePageAllocator flag then the buffers are allocated with VirtualAlloc() and are page aligned. If you specify RoundUpToPageSize your buffer size is taken as a base and the size of the buffer's housekeeping data is added on and the total size is then rounded up to the next multiple of the system's page size. If you specify SizeInPages then the bufferSize is multiplied by the system's page size to give the size of the memory that is allocated, the actual usable buffer size in such an instance is the memory allocated less the buffer's housekeeping data.

Enumerator:
SizeInBytes 
SizeInPages 
RoundUpToPageSize 
UseByteAllocator 
UsePageAllocator 
SizeBitsMask 
AllocatorBitsMask 


Constructor & Destructor Documentation

CBufferAllocator ( BufferSize  bufferSize,
BufferCount  maxFreeBuffers,
bool  log = true 
)

CBufferAllocator ( BufferSize  bufferSize,
BufferCount  maxFreeBuffers,
AllocationFlags  flags,
bool  log = true 
)

CBufferAllocator ( const CBufferAllocator rhs  ) 

~CBufferAllocator (  ) 

Reimplemented from CBufferAllocator.


Member Function Documentation

CBufferAllocator& operator= ( const CBufferAllocator rhs  ) 

CBufferAllocator::BufferCount EnlargePool ( BufferCount  buffersToAdd  )  [inherited]

Add buffersToAdd buffers to the pool.

JetByteTools::Core::IIndexedOpaqueUserData::UserDataIndex RequestUserDataSlot ( const JetByteTools::Core::_tstring name  )  [override, virtual, inherited]

Request a named user data slot and get an index to use in calls to methods on IIndexedOpaqueUserData.

Implements IProvideUserData.

UserDataIndex LockUserDataSlots (  )  [override, virtual, inherited]

Prevent more user data slots from being allocated. Returns the number of user data slots that have been allocated.

Implements IProvideUserData.

CSmartBuffer Allocate (  )  [override, virtual, inherited]

Allocate an instance of IBuffer, remember to call Release() on it when you're done with it.

Implements IAllocateBuffers.

CSmartBuffer AllocateCustomSizedBuffer ( BufferSize  bufferSize  )  [override, inherited]

CSmartBuffer AllocateCustomSizedBuffer ( BufferSize  bufferSize  )  [override, pure virtual, inherited]

Creates a buffer that is a specific size rather than the size that the allocator usually creates. These buffers are currently NOT pooled and are deleted when the last reference is released.

Implements IAllocateBuffer.

void AllocateBuffers ( size_t  numBuffers,
CBufferChain buffers 
) [override, virtual, inherited]

Implements IAllocateBuffers.

void AllocateBuffersForBytes ( size_t  numBytes,
CBufferChain buffers 
) [override, virtual, inherited]

Implements IAllocateBuffers.

IAllocateBuffers::BufferSize GetBufferSize (  )  const [override, virtual, inherited]

If an allocator is supplied or if any AllocationFlags other than SizeInBytes is specified then the actual usable size of the buffer will not be known until the user data slots of the allocator have been locked. This happens automatically when the first buffer is allocated or can be done at any time prior to that by calling LockUserDataSlots() explicitly. If GetBufferSize() before the usable size of the buffer is known then an exception is thrown.

Implements IAllocateBuffers.

bool Flush (  )  [override, virtual, inherited]

Flushes the allocator. Use with care as this forces active buffers to be released and destroyed! Generally only called as part of process cleanup and even then only to aid in buffer leak tracking.

Implements IAllocateBuffers.

CBufferAllocator::BufferCount GetNumActive (  )  const [inherited]

CBufferAllocator::BufferCount GetNumPooled (  )  const [inherited]

void IterateActiveList ( CallbackUserData  userData,
const BufferIterationCallback &  callback 
) [inherited]

static void AllocateDefaultUserDataIndices ( JetByteTools::Core::IProvideUserData dataProvider  )  [static, protected, inherited]


Member Data Documentation

const CBufferAllocator::BufferCount NoPooledBuffers = std::numeric_limits<CBufferAllocator::BufferCount>::max() [static, inherited]

Pass this value as maxFreeBuffers to constructors to create an allocator that doesn't pool buffers at all.

const CBufferAllocator::BufferCount MaxBufferCount = std::numeric_limits<CBufferAllocator::BufferCount>::max() - 1 [static, inherited]


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