Allocator Class

Inheritance diagram of Allocator

class Allocator(width, height)

Rectangular area allocation algorithm.

Initialise with a given width and height, then repeatedly call alloc to retrieve free regions of the area and protect that area from future allocations.

Allocator uses a fairly simple strips-based algorithm. It performs best when rectangles are allocated in decreasing height order.

Constructor:

__init__(width, height)

Create an Allocator of the given size.

Parameters:
  • width (int) – Width of the allocation region.
  • height (int) – Height of the allocation region.

Methods:

alloc(width, height) Get a free area in the allocator of the given size.
get_fragmentation() Get the fraction of area that’s unlikely to ever be used, based on current allocation behaviour.
get_usage() Get the fraction of area already allocated.

Methods

Allocator.alloc(width, height)

Get a free area in the allocator of the given size.

After calling alloc, the requested area will no longer be used. If there is not enough room to fit the given area AllocatorException is raised.

Parameters:
  • width (int) – Width of the area to allocate.
  • height (int) – Height of the area to allocate.
Return type:

int, int

Returns:

The X and Y coordinates of the bottom-left corner of the allocated region.

Allocator.get_fragmentation()

Get the fraction of area that’s unlikely to ever be used, based on current allocation behaviour.

This method is useful for debugging and profiling only.

Return type:float
Allocator.get_usage()

Get the fraction of area already allocated.

This method is useful for debugging and profiling only.

Return type:float

Table Of Contents

Previous topic

AllocatorException

Next topic

TextureAtlas Class