Panda3D

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:

## Public Member Functions
| SimpleAllocator (SimpleAllocator &&from) noexcept
| Move constructor. More...
| SimpleAllocator (size_t max_size, Mutex &lock)
SimpleAllocatorBlock * | alloc (size_t size, size_t alignment=1)
| Allocates a new block. More...
size_t | get_contiguous () const
| Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated. More...
SimpleAllocatorBlock * | get_first_block () const
| Returns a pointer to the first allocated block, or NULL if there are no allocated blocks. More...
size_t | get_max_size () const
| Returns the available space for allocated objects. More...
size_t | get_total_size () const
| Returns the total size of allocated objects. More...
bool | is_empty () const
| Returns true if there are no blocks allocated on this page, or false if there is at least one. More...
void | output (std::ostream &out) const
void | set_max_size (size_t max_size)
| Changes the available space for allocated objects. More...
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()

SimpleAllocator::SimpleAllocator | ( | SimpleAllocator && | from | ) |
| noexcept

Move constructor.

Definition at line 19 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.

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

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

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

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

- panda/src/gobj/simpleAllocator.h
- panda/src/gobj/simpleAllocator.cxx
- panda/src/gobj/simpleAllocator.I