DSC Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
DSC::Allocator Class Reference

flexible VRAM manager More...

#include <allocator.hpp>

Public Member Functions

 Allocator (int offset, int length)
 Creates a new allocator instance. More...
 
void * reserve (int size, int desired_offset=-1)
 The equivalent of malloc(size). More...
 
void release (void *address)
 frees the specified offset More...
 

Static Public Member Functions

static Allocator defaultMainSpriteVram ()
 
static Allocator defaultSubSpriteVram ()
 

Detailed Description

flexible VRAM manager

Constructor & Destructor Documentation

◆ Allocator()

DSC::Allocator::Allocator ( int  offset,
int  length 
)

Creates a new allocator instance.

Parameters
[in]offsetbase segment offset
[in]lengthbase segment length

This object allocates addresses in range [offset, offset+length-1]

Warning
Overlapping allocator segments are a bad idea! Make sure allocators' range don't conflict with each other.

Member Function Documentation

◆ release()

void DSC::Allocator::release ( void *  address)

frees the specified offset

Parameters
[in]addressoffset to free

No penalties if the address isn't in the allocator's range, it points to unallocated memory or has been previosuly released.

◆ reserve()

void * DSC::Allocator::reserve ( int  size,
int  desired_offset = -1 
)

The equivalent of malloc(size).

Parameters
[in]sizeData length (works best in units of 32 bytes a.k.a. the size of a 4bpp tile)
[in]desired_offsetIf positive, the block of specified size tries to be placed at [base segment offset + desired_offset]
Returns
the allocated block offset, or nullptr if allocation failed.

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