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
IBuffer::BufferSize 
BufferSize

Public Member Functions

 CBufferAllocator (const bool trackReferences, const BufferSize bufferSize, const BufferCount maxFreeBuffers, const 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 (const BufferSize bufferSize, const BufferCount maxFreeBuffers, const 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, const BufferSize bufferSize, const BufferCount maxFreeBuffers, const 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::Win32::IAllocateFixedSizedMemory &allocator, const 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::Win32::IAllocateFixedSizedMemory &allocator, const 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 ()
BufferCount EnlargePool (const BufferCount buffersToAdd)
 Add buffersToAdd buffers to the pool.
JetByteTools::Win32::IIndexedOpaqueUserData::UserDataIndex RequestUserDataSlot (const JetByteTools::Win32::_tstring &name) override
 Request a named user data slot and get an index to use in calls to methods on IIndexedOpaqueUserData.
JetByteTools::Win32::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 (const BufferSize bufferSize) 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
CSmartBuffer AllocateCustomSizedBuffer (const 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::Win32::IIndexedOpaqueUserData::UserDataIndex 
DefaultBufferChainIndex = 0
static const
JetByteTools::Win32::IIndexedOpaqueUserData::UserDataIndex 
NumberOfDefaultUserDataSlots = 1

Static Protected Member Functions

static void AllocateDefaultUserDataIndices (JetByteTools::Win32::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 ( const bool  trackReferences,
const BufferSize  bufferSize,
const BufferCount  maxFreeBuffers,
const 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 ( const BufferSize  bufferSize,
const BufferCount  maxFreeBuffers,
const 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,
const BufferSize  bufferSize,
const BufferCount  maxFreeBuffers,
const 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 (  ) 

Reimplemented in CBufferAllocator.


Member Function Documentation

CBufferAllocator::BufferCount EnlargePool ( const BufferCount  buffersToAdd  ) 

Add buffersToAdd buffers to the pool.

JetByteTools::Win32::IIndexedOpaqueUserData::UserDataIndex RequestUserDataSlot ( const JetByteTools::Win32::_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 ( const BufferSize  bufferSize  )  [override]

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

CSmartBuffer AllocateCustomSizedBuffer ( const 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::Win32::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 Wed Jan 17 15:20:48 2018 for The Server Framework - v6.9.1 by doxygen 1.5.3