Panda3D
Public Member Functions | List of all members
SimpleAllocator Class Reference

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

Inheritance diagram for SimpleAllocator:
VertexDataPage VertexDataSaveFile

Public Member Functions

 __init__ (SimpleAllocator from)
 Move constructor. More...
 
 __init__ (int max_size, Mutex lock)
 
SimpleAllocatorBlock alloc (int size, int alignment)
 Allocates a new block. More...
 
int getContiguous ()
 Returns an upper-bound estimate of the size of the largest contiguous block that may be allocated. More...
 
SimpleAllocatorBlock getFirstBlock ()
 Returns a pointer to the first allocated block, or NULL if there are no allocated blocks. More...
 
int getMaxSize ()
 Returns the available space for allocated objects. More...
 
int getTotalSize ()
 Returns the total size of allocated objects. More...
 
bool isEmpty ()
 Returns true if there are no blocks allocated on this page, or false if there is at least one. More...
 
 output (Ostream out)
 
 setMaxSize (int max_size)
 Changes the available space for allocated objects. More...
 
 write (Ostream out)
 

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.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( SimpleAllocator  from)

Move constructor.

◆ __init__() [2/2]

__init__ ( int  max_size,
Mutex  lock 
)

◆ alloc()

SimpleAllocatorBlock alloc ( int  size,
int  alignment 
)

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.

◆ getContiguous()

int getContiguous ( )

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.

◆ getFirstBlock()

SimpleAllocatorBlock getFirstBlock ( )

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

◆ getMaxSize()

int getMaxSize ( )

Returns the available space for allocated objects.

◆ getTotalSize()

int getTotalSize ( )

Returns the total size of allocated objects.

◆ isEmpty()

bool isEmpty ( )

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

◆ output()

output ( Ostream  out)

◆ setMaxSize()

setMaxSize ( int  max_size)

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().

◆ write()

write ( Ostream  out)