Class pyglet.graphics.allocation.Allocator

Buffer space allocation implementation.

Methods

  __init__(self, capacity)
Create an allocator for a buffer of the specified capacity.
  set_capacity(self, size)
Resize the maximum buffer size.
int alloc(self, size)
Allocate memory in the buffer.
  realloc(self, start, size, new_size)
Reallocate a region of the buffer.
  dealloc(self, start, size)
Free a region of the buffer.
(list, list) get_allocated_regions(self)
Get a list of (aggregate) allocated regions.
int get_fragmented_free_size(self)
Returns the amount of space unused, not including the final free block.
int get_free_size(self)
Return the amount of space unused.
float get_usage(self)
Return fraction of capacity currently allocated.
float get_fragmentation(self)
Return fraction of free space that is not expandable.
  __str__(self)
  __repr__(self)

Method Details

__init__

(Constructor) __init__(self, capacity)
Create an allocator for a buffer of the specified capacity.
Parameters:
capacity : int
Maximum size of the buffer.

set_capacity

set_capacity(self, size)

Resize the maximum buffer size.

The capacity cannot be reduced.

Parameters:
size : int
New maximum size of the buffer.

alloc

alloc(self, size)

Allocate memory in the buffer.

Raises AllocatorMemoryException if the allocation cannot be fulfilled.

Parameters:
size : int
Size of region to allocate.
Returns:
int: Starting index of the allocated region.

realloc

realloc(self, start, size, new_size)

Reallocate a region of the buffer.

This is more efficient than separate dealloc and alloc calls, as the region can often be resized in-place.

Raises AllocatorMemoryException if the allocation cannot be fulfilled.

Parameters:
start : int
Current starting index of the region.
size : int
Current size of the region.
new_size : int
New size of the region.

dealloc

dealloc(self, start, size)
Free a region of the buffer.
Parameters:
start : int
Starting index of the region.
size : int
Size of the region.

get_allocated_regions

get_allocated_regions(self)

Get a list of (aggregate) allocated regions.

The result of this method is (starts, sizes), where starts is a list of starting indices of the regions and sizes their corresponding lengths.

Returns: (list, list)