Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Cogs::Memory::Allocator Class Reference

Base allocator implementation. More...

#include <Allocator.h>

Public Member Functions

 Allocator ()=default
 
virtual ~Allocator ()=default
 
virtual void * allocate (size_t size, size_t alignment=0, MemBlockType type=MemBlockType::Block)
 Allocate raw memory.
 
virtual void deallocate (void *ptr, size_t size, MemBlockType type=MemBlockType::Block)
 Deallocate the memory block at the given pointer, with the given size.
 
virtual void changeType (void *ptr, size_t size, MemBlockType oldType, MemBlockType newType)
 
virtual size_t getAllocatedBytes () const
 Return the number of bytes currently allocated by this allocator.
 
virtual size_t getAllocationCount () const
 Return the number of allocations currently allocated by this allocator.
 

Static Public Member Functions

static AllocatordefaultAllocator ()
 Gets the system default allocator.
 
static AllocatoroverflowAllocator ()
 

Protected Attributes

Cogs::Atomic< size_t > allocated {0}
 
Cogs::Atomic< size_t > allocations {0}
 

Detailed Description

Base allocator implementation.

Allocates raw, uninitialized heap memory.

Constructor & Destructor Documentation

◆ Allocator()

Cogs::Memory::Allocator::Allocator ( )
default

◆ ~Allocator()

virtual Cogs::Memory::Allocator::~Allocator ( )
virtualdefault

Member Function Documentation

◆ allocate()

void * Cogs::Memory::Allocator::allocate ( size_t  size,
size_t  alignment = 0,
MemBlockType  type = MemBlockType::Block 
)
virtual

Allocate raw memory.

Parameters
sizeSize in bytes of requested allocation.
alignmentAlignment in bytes.
Returns
Pointer to allocated memory.

References Cogs::Memory::kDefaultAlignment, LOG_ERROR, and Cogs::logger.

Referenced by Cogs::Memory::StdAllocator< T >::allocate(), Cogs::Memory::create(), Cogs::Collections::SmallVectorImplBase< T, isPod >::grow(), and Cogs::Collections::SmallVectorBase::growPod().

◆ changeType()

void Cogs::Memory::Allocator::changeType ( void *  ptr,
size_t  size,
MemBlockType  oldType,
MemBlockType  newType 
)
virtual

◆ deallocate()

void Cogs::Memory::Allocator::deallocate ( void *  ptr,
size_t  size,
MemBlockType  type = MemBlockType::Block 
)
virtual

Deallocate the memory block at the given pointer, with the given size.

The size parameter may be given to enable extra checking when releasing memory.

Parameters
ptrPointer to previously allocated memory.
sizeSize in bytes of the given allocation.

Referenced by Cogs::Memory::StdAllocator< T >::deallocate(), Cogs::Memory::destroy(), Cogs::Collections::SmallVectorBase::growPod(), and Cogs::Collections::SmallVectorImpl< T >::release().

◆ defaultAllocator()

Cogs::Memory::Allocator * Cogs::Memory::Allocator::defaultAllocator ( )
static

Gets the system default allocator.

◆ getAllocatedBytes()

virtual size_t Cogs::Memory::Allocator::getAllocatedBytes ( ) const
inlinevirtual

Return the number of bytes currently allocated by this allocator.

◆ getAllocationCount()

virtual size_t Cogs::Memory::Allocator::getAllocationCount ( ) const
inlinevirtual

Return the number of allocations currently allocated by this allocator.

◆ overflowAllocator()

Cogs::Memory::Allocator * Cogs::Memory::Allocator::overflowAllocator ( )
static

Gets the system default overflow allocator, used by collections that may overflow a custom given allocator.

Member Data Documentation

◆ allocated

Cogs::Atomic<size_t> Cogs::Memory::Allocator::allocated {0}
protected

◆ allocations

Cogs::Atomic<size_t> Cogs::Memory::Allocator::allocations {0}
protected

The documentation for this class was generated from the following files: