Jo Engine  2023.08.26
Jo Sega Saturn Engine
Macros | Enumerations | Functions
malloc.h File Reference

Jo Engine Malloc. More...

Go to the source code of this file.

Macros

#define JO_MALLOC_MAX_MEMORY_ZONE
 Define the total of memory zone available through jo_add_memory_zone() More...
 

Enumerations

enum  jo_extended_ram_cartridge_type { CART_NONE, CART_8MBits, CART_32MBits }
 Extended RAM cartridge type. More...
 
enum  jo_malloc_behaviour { JO_FAST_ALLOCATION, JO_MALLOC_TRY_REUSE_BLOCK, JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE }
 Malloc behaviour JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE | ^ | | Speed efficiency | | V | JO_MALLOC_TRY_REUSE_BLOCK | ^ | | Speed efficiency | | V | JO_FAST_ALLOCATION. More...
 

Functions

void * jo_malloc_with_behaviour (unsigned int n, const jo_malloc_behaviour behaviour)
 dynamic memory allocator with specific behaviour More...
 
static __jo_force_inline void * jo_malloc (unsigned int n)
 dynamic memory allocator More...
 
void jo_free (const void *const p)
 function frees the memory space pointed to by p More...
 
void jo_reduce_memory_fragmentation (void)
 Reduce memory fragmentation for faster memory allocation. More...
 
void jo_add_memory_zone (unsigned char *ptr, const unsigned int size_in_bytes)
 Register a memory segment for jo_malloc() usage. More...
 
int jo_memory_usage_percent (void)
 Get memory usage percent. More...
 
int jo_memory_fragmentation (void)
 Get memory fragmentation (Number of fragment in memory) More...
 

Detailed Description

Jo Engine Malloc.

Author
Johannes Fetz
Bug:
No known bugs.

Macro Definition Documentation

◆ JO_MALLOC_MAX_MEMORY_ZONE

#define JO_MALLOC_MAX_MEMORY_ZONE

Define the total of memory zone available through jo_add_memory_zone()

Remarks
MAIN RAM + 32MB RAM Extension
Warning
Minimum is 9 for the engine with all modules

Enumeration Type Documentation

◆ jo_extended_ram_cartridge_type

Extended RAM cartridge type.

Enumerator
CART_NONE 

No cartridge.

CART_8MBits 

1 Mb cartridge

CART_32MBits 

4 Mb cartridge

◆ jo_malloc_behaviour

Malloc behaviour JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE | ^ | | Speed efficiency | | V | JO_MALLOC_TRY_REUSE_BLOCK | ^ | | Speed efficiency | | V | JO_FAST_ALLOCATION.

Enumerator
JO_FAST_ALLOCATION 

Default behaviour.

JO_MALLOC_TRY_REUSE_BLOCK 

A little bit slower but reduce memory fragmentation.

JO_MALLOC_TRY_REUSE_SAME_BLOCK_SIZE 

A little bit slower than JO_MALLOC_TRY_REUSE_BLOCK but reduce memory usage.

Function Documentation

◆ jo_add_memory_zone()

void jo_add_memory_zone ( unsigned char *  ptr,
const unsigned int  size_in_bytes 
)

Register a memory segment for jo_malloc() usage.

Parameters
ptrPointer to the beginning of the memory segment
size_in_bytesSize of the memory segment in bytes
Remarks
See also JO_MALLOC_MAX_MEMORY_ZONE

◆ jo_free()

void jo_free ( const void *const  p)

function frees the memory space pointed to by p

Parameters
ppointer that must have been returned by a previous call to jo_malloc()

◆ jo_malloc()

static __jo_force_inline void* jo_malloc ( unsigned int  n)
static

dynamic memory allocator

Parameters
nSegment size
Returns
a pointer to the allocated memory or NULL if failed

◆ jo_malloc_with_behaviour()

void* jo_malloc_with_behaviour ( unsigned int  n,
const jo_malloc_behaviour  behaviour 
)

dynamic memory allocator with specific behaviour

Parameters
nSegment size
behaviourAllocation Behaviour
Returns
a pointer to the allocated memory or NULL if failed

◆ jo_memory_fragmentation()

int jo_memory_fragmentation ( void  )

Get memory fragmentation (Number of fragment in memory)

Returns
Memory fragmentation
Remarks
jo_printf(0, 0, "Dynamic memory fragmentation count: %d ", jo_memory_fragmentation());

◆ jo_memory_usage_percent()

int jo_memory_usage_percent ( void  )

Get memory usage percent.

Returns
memory usage percent
Remarks
jo_printf(0, 0, "Dynamic memory usage: %d%% ", jo_memory_usage_percent());

◆ jo_reduce_memory_fragmentation()

void jo_reduce_memory_fragmentation ( void  )

Reduce memory fragmentation for faster memory allocation.

Remarks
This function can be slow