Cogs.Core
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>

Inheritance diagram for Cogs::Memory::Allocator:
Cogs::Core::CoreAllocator Cogs::Core::TextureAllocator Cogs::ResourceAllocator

Public Member Functions

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.

Definition at line 29 of file Allocator.h.

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.

Reimplemented in Cogs::ResourceAllocator, Cogs::Core::CoreAllocator, and Cogs::Core::TextureAllocator.

Definition at line 29 of file Allocator.cpp.

Referenced by Cogs::Core::CoreAllocator::allocate(), and Cogs::Core::TextureAllocator::allocate().

◆ changeType()

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

Definition at line 72 of file Allocator.cpp.

◆ 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.

Reimplemented in Cogs::Core::TextureAllocator, Cogs::ResourceAllocator, and Cogs::Core::CoreAllocator.

Definition at line 58 of file Allocator.cpp.

Referenced by Cogs::Core::TextureAllocator::deallocate(), and Cogs::Core::CoreAllocator::deallocate().

◆ defaultAllocator()

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

Gets the system default allocator.

Definition at line 17 of file Allocator.cpp.

Referenced by Cogs::Factory::createDevice().

◆ getAllocatedBytes()

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

Return the number of bytes currently allocated by this allocator.

Reimplemented in Cogs::Core::CoreAllocator.

Definition at line 65 of file Allocator.h.

◆ getAllocationCount()

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

Return the number of allocations currently allocated by this allocator.

Reimplemented in Cogs::Core::CoreAllocator.

Definition at line 68 of file Allocator.h.

◆ 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.

Definition at line 24 of file Allocator.cpp.

Member Data Documentation

◆ allocated

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

Definition at line 71 of file Allocator.h.

◆ allocations

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

Definition at line 72 of file Allocator.h.


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