BlockBufferAllocator< PARENT_ALLOCATOR > Class Template Reference

#include <blockbufferallocator.h>

详细描述

template<typename PARENT_ALLOCATOR>
class maxon::BlockBufferAllocator< PARENT_ALLOCATOR >

Block buffer allocator. A fixed allocator which contains the size of the initialized memoryblock/size. The first memory request (and any Resize calls) that are smaller than this size will return this static memory. All other requests will be routed to the PARENT_ALLOCATOR. The BlockBufferAllocator is not thread-safe!

Here an example for the use of a BlockBufferAllocator :

StringEncodingRef utf8encoder = StringEncodings::Get (Id( "utf8" )); BaseArray<Char, 16, BASEARRAYFLAGS::NONE, BlockBufferAllocator<NullAllocator>> dstArray(BlockBufferAllocator<NullAllocator>(block.GetFirst(), block. GetCount ())); dstArray.EnsureCapacity(block. GetCount (), true ); iferr (utf8encoder.EncodeString(_txt, dstArray)) { }

In the example a BaseArray will use the guaranteed 1024 bytes from the stack / fixed allocator first. Only when the BaseArray grows bigger than 1024 characters more memory from the DefaultAllocator will be fetched. This is a convenient way to allow routines be flexible without (length) limits, but avoiding constant unnecessary memory allocations.

Template Parameters
PARENT_ALLOCATOR The allocator that shall be used when a request cannot be satisfied using the static memory.

公共成员函数

  BlockBufferAllocator (void *memoryBuffer, Int memBlockSize)
  BlockBufferAllocator (const BlockBufferAllocator &parent)
Int   ComputeArraySize ( Int currentSize, Int increment, Int minChunkSize)
void *  Alloc ( Int32 s, MAXON_SOURCE_LOCATION_DECLARATION )
void *  Alloc ( Int64 s, MAXON_SOURCE_LOCATION_DECLARATION )
void *  Realloc (void *p, Int32 n, MAXON_SOURCE_LOCATION_DECLARATION )
void *  Realloc (void *p, Int64 n, MAXON_SOURCE_LOCATION_DECLARATION )
template<typename T >
void  Free (T *&p)
Bool   IsCompatibleWithDefaultAllocator (void *p) const

私有成员函数

  BlockBufferAllocator ()

Private Attributes

void *  _memoryBuffer
Int   _memBlockSize
Bool   _memoryUsed
PARENT_ALLOCATOR  _allocator

构造函数 & 析构函数文档编制

◆  BlockBufferAllocator() [1/3]

BlockBufferAllocator ( )
private

Default constructor, disabled because the pointer and size is needed.

◆  BlockBufferAllocator() [2/3]

BlockBufferAllocator ( void *  memoryBuffer ,
Int   memBlockSize  
)

Constructor, with the given memory block.

参数
[in] memoryBuffer Pointer to memory that is mapped to the allocator.
[in] memBlockSize Size of the memory block.

◆  BlockBufferAllocator() [3/3]

BlockBufferAllocator ( const BlockBufferAllocator < PARENT_ALLOCATOR > &  parent )
explicit

Copy constructor.

成员函数文档编制

◆  ComputeArraySize()

Int ComputeArraySize ( Int   currentSize ,
Int   increment ,
Int   minChunkSize  
)

Computes the new size for a growing array THREADSAFE.

参数
[in] currentSize Current number of elements.
[in] increment Number of elements to be added (>= 1)
[in] minChunkSize The minimum number of elements upon array creation.
返回
New number of elements.

◆  Alloc() [1/2]

void* Alloc ( Int32   s ,
MAXON_SOURCE_LOCATION_DECLARATION    
)

Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode.

参数
[in] s Block size in bytes (values < 0 will return nullptr)
[in] allocLocation Pass MAXON_SOURCE_LOCATION(_NAME) to add the current source line and file.
返回
Memory block address or nullptr.

◆  Alloc() [2/2]

void* Alloc ( Int64   s ,
MAXON_SOURCE_LOCATION_DECLARATION    
)

Allocates a memory block. The memory is not cleared, it may contain a certain byte pattern in debug mode.

参数
[in] s Block size in bytes (values < 0 will return nullptr)
[in] allocLocation Pass MAXON_SOURCE_LOCATION(_NAME) to add the current source line and file.
返回
Memory block address or nullptr.

◆  Realloc() [1/2]

void* Realloc ( void *  p ,
Int32   n ,
MAXON_SOURCE_LOCATION_DECLARATION    
)

Resizes a memory block. The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. The additional memory is not cleared, it may contain a certain byte pattern in debug mode. In case that p is a nullptr the function behaves like Alloc. If the function fails to allocate the requested block of memory a nullptr is returned and the memory block pointed to by argument p is not deallocated (it is still valid with its contents unchanged). THREADSAFE.

参数
[in] p Current memory block (can be nullptr)
[in] n New block size in bytes (values < 0 will return nullptr)
[in] allocLocation Pass MAXON_SOURCE_LOCATION(_NAME) to add the current source line and file.
返回
Memory block address or nullptr if resize is not possible (p is still valid in this case)

◆  Realloc() [2/2]

void* Realloc ( void *  p ,
Int64   n ,
MAXON_SOURCE_LOCATION_DECLARATION    
)

Resizes a memory block. The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. The additional memory is not cleared, it may contain a certain byte pattern in debug mode. In case that p is a nullptr the function behaves like Alloc. If the function fails to allocate the requested block of memory a nullptr is returned and the memory block pointed to by argument p is not deallocated (it is still valid with its contents unchanged). THREADSAFE.

参数
[in] p Current memory block (can be nullptr)
[in] n New block size in bytes (values < 0 will return nullptr)
[in] allocLocation Pass MAXON_SOURCE_LOCATION(_NAME) to add the current source line and file.
返回
Memory block address or nullptr if resize is not possible (p is still valid in this case)

◆  Free()

void Free ( T *&  p )

Frees a memory block.

参数
[in,out] p Memory block address (can be nullptr, will be nullptr after return)

◆  IsCompatibleWithDefaultAllocator()

Bool IsCompatibleWithDefaultAllocator ( void *  p ) const

Returns if a memory block allocated via this allocator can be reallocated or freed by the DefaultAllocator .

参数
[in] p Memory block address.
返回
True if the memory block can be reallocated or freed by the DefaultAllocator .

Member Data Documentation

◆  _memoryBuffer

void* _memoryBuffer private

◆  _memBlockSize

Int _memBlockSize
private

◆  _memoryUsed

Bool _memoryUsed
private

◆  _allocator

PARENT_ALLOCATOR _allocator private
FieldOutputBlock::GetCount
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
定义: c4d_fielddata.h:375
maxon::Classes::Get
const Class< R > & Get(const Id &cls)
定义: objectbase.h:1903
iferr
#define iferr(...)
定义: errorbase.h:380