SaturnRingLibrary 0.7
SGL wrapper
 
Loading...
Searching...
No Matches
SRL::Memory Class Reference

Detailed Description

Dynamic memory management.

#include <srl_memory.hpp>

Classes

class  CartRam
 Malloc for expansion cart RAM. More...
 
class  HighWorkRam
 Malloc for main system RAM. More...
 
class  LowWorkRam
 Malloc for slower system RAM. More...
 
struct  Report
 Contains report of the state. More...
 

Public Types

enum  Zone { HWRam = 0 , LWRam = 1 , CartRam = 2 }
 Memory zone codes. More...
 

Static Public Member Functions

static void Free (void *ptr)
 Free allocated memory from any memory zone.
 
static size_t GetFreeSpace (const Zone zone)
 Gets total size of the free space in the memory zone.
 
static size_t GetSize (const Zone zone)
 Gets total size of the memory zone.
 
static size_t GetUsedSpace (const Zone zone)
 Gets total size of the used space in the memory zone.
 
static void Initialize ()
 Initialize memory.
 
static void * Malloc (size_t size, const SRL::Memory::Zone zone)
 Allocate some memory in specified zone.
 
static void MemSet (void *destination, const uint8_t value, const size_t length)
 Det memory to some value.
 
static void * PlacementMalloc (size_t size, uint32_t address)
 Allocate some memory in zone containing specified address.
 
static void * PlacementMalloc (size_t size, void *address)
 Allocate some memory in zone containing specified address.
 

Related Symbols

(Note that these are not member symbols.)

#define autonew   new(reinterpret_cast<uint32_t>(this))
 Allocates memory in the same zone as current context.
 
#define cartnew   new (SRL::Memory::Zone::CartRam)
 new keyword for expansion cartridge RAM
 
#define hwnew   new
 new keyword for high work RAM
 
#define lwnew   new (SRL::Memory::Zone::LWRam)
 new keyword for low work RAM
 

Member Enumeration Documentation

◆ Zone

Memory zone codes.

Enumerator
HWRam 

High (main) system RAM.

LWRam 

Low system RAM.

CartRam 

Expansion cart RAM.

Member Function Documentation

◆ Free()

static void SRL::Memory::Free ( void * ptr)
inlinestatic

Free allocated memory from any memory zone.

Parameters
ptrPointer to allocated memory

◆ GetFreeSpace()

static size_t SRL::Memory::GetFreeSpace ( const Zone zone)
inlinestatic

Gets total size of the free space in the memory zone.

Parameters
zoneMemory zone
Returns
Number of bytes

◆ GetSize()

static size_t SRL::Memory::GetSize ( const Zone zone)
inlinestatic

Gets total size of the memory zone.

Parameters
zoneMemory zone
Returns
Number of bytes

◆ GetUsedSpace()

static size_t SRL::Memory::GetUsedSpace ( const Zone zone)
inlinestatic

Gets total size of the used space in the memory zone.

Parameters
zoneMemory zone
Returns
Number of bytes

◆ Malloc()

static void * SRL::Memory::Malloc ( size_t size,
const SRL::Memory::Zone zone )
inlinestatic

Allocate some memory in specified zone.

Parameters
sizeNumber of bytes to allocate
zoneMemory zone
Returns
Pointer to the allocated space in memory

◆ MemSet()

static void SRL::Memory::MemSet ( void * destination,
const uint8_t value,
const size_t length )
inlinestatic

Det memory to some value.

Parameters
destinationDestination to set
valueValue to set
lengthData length to set

◆ PlacementMalloc() [1/2]

static void * SRL::Memory::PlacementMalloc ( size_t size,
uint32_t address )
inlinestatic

Allocate some memory in zone containing specified address.

Parameters
sizeNumber of bytes to allocate
addressAddress in the memory where object should be allocated
Returns
Pointer to the allocated space in memory

◆ PlacementMalloc() [2/2]

static void * SRL::Memory::PlacementMalloc ( size_t size,
void * address )
inlinestatic

Allocate some memory in zone containing specified address.

Parameters
sizeNumber of bytes to allocate
addressAddress in the memory where object should be allocated
Returns
Pointer to the allocated space in memory

Friends And Related Symbol Documentation

◆ autonew

#define autonew   new(reinterpret_cast<uint32_t>(this))
related

Allocates memory in the same zone as current context.

Warning
Extreme cation is required.
This will allocate new object in the same zone as the this keyword is present in.
class MyFirstThing { }
class MySecondThing
{
MyFirstThing * thing;
MySecondThing() {
// Allocate object MyFirstThing in the same memory zone as MySecondThing
this->thing = autonew MyFirstThing();
}
}
void main()
{
// Allocates MySecondThing object in the Low RAM, which in term in its constructor allocates
// MyFirstThing object in the same zone (Low RAM)
MySecondThing* first = lwnew MySecondThing();
// Allocates MySecondThing object in the High RAM, which in term in its constructor allocates
// MyFirstThing object in the same zone (High RAM)
// For High RAM, keywords new or hwnew can be both used
MySecondThing* second = new MySecondThing();
}
#define lwnew
new keyword for low work RAM
Definition srl_memory.hpp:983

◆ cartnew

#define cartnew   new (SRL::Memory::Zone::CartRam)
related

new keyword for expansion cartridge RAM

class MyFirstThing { }
void main()
{
// Allocates MyFirstThing in the cart RAM
MyFirstThing* second = cartnew MyFirstThing();
}
#define cartnew
new keyword for expansion cartridge RAM
Definition srl_memory.hpp:969

◆ hwnew

#define hwnew   new
related

new keyword for high work RAM

class MyFirstThing { }
void main()
{
// Allocates MyFirstThing in the high RAM
MyFirstThing* second = hwnew MyFirstThing();
// For High RAM, keywords new or hwnew can be both used
MyFirstThing* second = new MyFirstThing();
}
#define hwnew
new keyword for high work RAM
Definition srl_memory.hpp:1000

◆ lwnew

#define lwnew   new (SRL::Memory::Zone::LWRam)
related

new keyword for low work RAM

class MyFirstThing { }
void main()
{
// Allocates MyFirstThing in the low RAM
MyFirstThing* second = lwnew MyFirstThing();
}