Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
SimpleAllocator Class Reference

An implementation of a very simple block allocator. More...

#include "simpleAllocator.h"

Inheritance diagram for SimpleAllocator:
LinkedListNode VertexDataPage VertexDataSaveFile

Public Member Functions

 SimpleAllocator (SimpleAllocator &&from) noexcept
 Move constructor.
 
 SimpleAllocator (size_t max_size, Mutex &lock)
 
SimpleAllocatorBlockalloc (size_t size, size_t alignment=1)
 Allocates a new block.
 
size_t get_contiguous () const
 Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated.
 
SimpleAllocatorBlockget_first_block () const
 Returns a pointer to the first allocated block, or NULL if there are no allocated blocks.
 
size_t get_max_size () const
 Returns the available space for allocated objects.
 
size_t get_total_size () const
 Returns the total size of allocated objects.
 
bool is_empty () const
 Returns true if there are no blocks allocated on this page, or false if there is at least one.
 
void output (std::ostream &out) const
 
void set_max_size (size_t max_size)
 Changes the available space for allocated objects.
 
void write (std::ostream &out) const
 

Friends

class SimpleAllocatorBlock
 

Detailed Description

An implementation of a very simple block allocator.

This class can allocate ranges of nonnegative integers within a specified upper limit; it uses a simple first-fit algorithm to find the next available space.

Definition at line 29 of file simpleAllocator.h.

Constructor & Destructor Documentation

◆ SimpleAllocator() [1/2]

SimpleAllocator::SimpleAllocator ( size_t max_size,
Mutex & lock )
inlineexplicit

Definition at line 17 of file simpleAllocator.I.

◆ SimpleAllocator() [2/2]

SimpleAllocator::SimpleAllocator ( SimpleAllocator && from)
noexcept

Move constructor.

Definition at line 19 of file simpleAllocator.cxx.

◆ ~SimpleAllocator()

SimpleAllocator::~SimpleAllocator ( )
virtual

Definition at line 50 of file simpleAllocator.cxx.

Member Function Documentation

◆ alloc()

SimpleAllocatorBlock * SimpleAllocator::alloc ( size_t size,
size_t alignment = 1 )
inline

Allocates a new block.

Returns NULL if a block of the requested size cannot be allocated.

To free the allocated block, call block->free(), or simply delete the block pointer.

Definition at line 34 of file simpleAllocator.I.

◆ get_contiguous()

size_t SimpleAllocator::get_contiguous ( ) const
inline

Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated.

It is guaranteed that an attempt to allocate a block larger than this will fail, though it is not guaranteed that an attempt to allocate a block this size or smaller will succeed.

Definition at line 85 of file simpleAllocator.I.

◆ get_first_block()

SimpleAllocatorBlock * SimpleAllocator::get_first_block ( ) const
inline

Returns a pointer to the first allocated block, or NULL if there are no allocated blocks.

Definition at line 95 of file simpleAllocator.I.

Referenced by VertexDataPage::get_first_block().

◆ get_max_size()

size_t SimpleAllocator::get_max_size ( ) const
inline

Returns the available space for allocated objects.

Definition at line 62 of file simpleAllocator.I.

◆ get_total_size()

size_t SimpleAllocator::get_total_size ( ) const
inline

Returns the total size of allocated objects.

Definition at line 53 of file simpleAllocator.I.

Referenced by VertexDataSaveFile::get_used_file_size().

◆ is_empty()

bool SimpleAllocator::is_empty ( ) const
inline

Returns true if there are no blocks allocated on this page, or false if there is at least one.

Definition at line 44 of file simpleAllocator.I.

◆ output()

void SimpleAllocator::output ( std::ostream & out) const

Definition at line 65 of file simpleAllocator.cxx.

◆ set_max_size()

void SimpleAllocator::set_max_size ( size_t max_size)
inline

Changes the available space for allocated objects.

This will not affect any already-allocated objects, but will have an effect on future calls to alloc().

Definition at line 73 of file simpleAllocator.I.

◆ write()

void SimpleAllocator::write ( std::ostream & out) const

Definition at line 75 of file simpleAllocator.cxx.

Friends And Related Symbol Documentation

◆ SimpleAllocatorBlock

friend class SimpleAllocatorBlock
friend

Definition at line 84 of file simpleAllocator.h.


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