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

CBufferAllocator Class Reference
[Opaque user dataI/O BuffersAsynchronous I/O]

Inheritance diagram for CBufferAllocator:
Collaboration diagram for CBufferAllocator:

List of all members.


Detailed Description

An implementation of IAllocateBuffers which pools buffer instances for later reuse.

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, AllocationFlags flags=SizeInBytes)
 Create an allocator for buffers of the requested size and keep up to maxFreeBuffers buffers in a pool for reuse. See AlocationFlags for details of how you can tune the buffer allocator. Pass NoPooledSockets as maxFreeBuffers to create an allocator that doesn't pool buffers at all, pass zero to pool every buffer ever created, or the number that you require kept in the pool for reuse.
 CBufferAllocator (IMonitorBufferAllocation &monitor, BufferSize bufferSize, BufferCount maxFreeBuffers, AllocationFlags flags=SizeInBytes)
 Create an allocator for buffers of the requested size and keep up to maxFreeBuffers buffers in a pool for reuse. Provide monitoring information via the supplied instance of the IMonitorBufferAllocation interface. See AlocationFlags for details of how you can tune the buffer allocator. Pass NoPooledSockets as maxFreeBuffers to create an allocator that doesn't pool buffers at all, pass zero to pool every buffer ever created, or the number that you require kept in the pool for reuse.
 CBufferAllocator (JetByteTools::Core::IAllocateFixedSizedMemory &allocator, BufferCount maxFreeBuffers)
 Create an allocator for buffers using the supplied memory allocator and keep up to maxFreeBuffers buffers in a pool for reuse. Note that the fixed sized memory allocator will be used to allocate the buffer and user data and the actual available buffer size will depend on how much user data is allocated for each buffer.
 CBufferAllocator (IMonitorBufferAllocation &monitor, JetByteTools::Core::IAllocateFixedSizedMemory &allocator, BufferCount maxFreeBuffers)
 Create an allocator for buffers using the supplied memory allocator and keep up to maxFreeBuffers buffers in a pool for reuse. Provide monitoring information via the supplied instance of the IMonitorBufferAllocation interface. Note that the fixed sized memory allocator will be used to allocate the buffer and user data and the actual available buffer size will depend on how much user data is allocated for each buffer.
 CBufferAllocator (const CBufferAllocator &rhs)
 ~CBufferAllocator () override
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
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)
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.

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

typedef IBuffer::BufferSize BufferSize [inherited]


Member Enumeration Documentation

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,
AllocationFlags  flags = SizeInBytes 
)

Create an allocator for buffers of the requested size and keep up to maxFreeBuffers buffers in a pool for reuse. See AlocationFlags for details of how you can tune the buffer allocator. Pass NoPooledSockets as maxFreeBuffers to create an allocator that doesn't pool buffers at all, pass zero to pool every buffer ever created, or the number that you require kept in the pool for reuse.

CBufferAllocator ( IMonitorBufferAllocation monitor,
BufferSize  bufferSize,
BufferCount  maxFreeBuffers,
AllocationFlags  flags = SizeInBytes 
)

Create an allocator for buffers of the requested size and keep up to maxFreeBuffers buffers in a pool for reuse. Provide monitoring information via the supplied instance of the IMonitorBufferAllocation interface. See AlocationFlags for details of how you can tune the buffer allocator. Pass NoPooledSockets as maxFreeBuffers to create an allocator that doesn't pool buffers at all, pass zero to pool every buffer ever created, or the number that you require kept in the pool for reuse.

Create an allocator for buffers using the supplied memory allocator and keep up to maxFreeBuffers buffers in a pool for reuse. Note that the fixed sized memory allocator will be used to allocate the buffer and user data and the actual available buffer size will depend on how much user data is allocated for each buffer.

Create an allocator for buffers using the supplied memory allocator and keep up to maxFreeBuffers buffers in a pool for reuse. Provide monitoring information via the supplied instance of the IMonitorBufferAllocation interface. Note that the fixed sized memory allocator will be used to allocate the buffer and user data and the actual available buffer size will depend on how much user data is allocated for each buffer.

CBufferAllocator ( const CBufferAllocator rhs  ) 

~CBufferAllocator (  )  [override]

Reimplemented in CBufferAllocator.


Member Function Documentation

CBufferAllocator& operator= ( const CBufferAllocator rhs  ) 

CBufferAllocator::BufferCount EnlargePool ( BufferCount  buffersToAdd  ) 

Add buffersToAdd buffers to the pool.

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

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

Implements IProvideUserData.

UserDataIndex LockUserDataSlots (  )  [override, virtual]

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]

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

Implements IAllocateBuffers.

CSmartBuffer AllocateCustomSizedBuffer ( BufferSize  bufferSize  )  [override]

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

Implements IAllocateBuffers.

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

Implements IAllocateBuffers.

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

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]

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

CBufferAllocator::BufferCount GetNumPooled (  )  const

void IterateActiveList ( CallbackUserData  userData,
const BufferIterationCallback &  callback 
)

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.

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


Member Data Documentation

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

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]


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