Super Mario 64 Source
A Super Mario 64 decompilation, brought to you by a bunch of clever folks.
Functions | Variables
gd_memory.c File Reference

This file contains the functions need to manage allocation in goddard's heap. More...

#include <ultra64.h>
#include "gd_memory.h"
#include "debug_utils.h"
#include "renderer.h"

Functions

void empty_mem_block (struct GMemBlock *block)
 Empty a GMemBlock into a default state. More...
 
struct GMemBlockinto_free_memblock (struct GMemBlock *block)
 Transform a GMemBlock into a free block that points to memory available for allocation. More...
 
struct GMemBlockmake_mem_block (u32 blockType, u8 permFlag)
 Allocate a new GMemBlock structure of the given type and permanence. More...
 
u32 print_list_stats (struct GMemBlock *block, s32 printBlockInfo, s32 permanence)
 Print information (size, entries) about the GMemBlock list. More...
 
u32 gd_free_mem (void *ptr)
 Free memory allocated on the goddard heap. More...
 
voidgd_request_mem (u32 size, u8 permanence)
 Request a pointer to goddard heap memory of at least size and of the same permanence. More...
 
struct GMemBlockgd_add_mem_to_heap (u32 size, u32 addr, u8 permanence)
 Add memory of size at addr to the goddard heap for later allocation. More...
 
void init_mem_block_lists (void)
 NULL the various GMemBlock list heads. More...
 
void mem_stats (void)
 Print summary information about all used, free, and empty GMemBlocks. More...
 

Variables

static struct GMemBlocksFreeBlockListHead
 
static struct GMemBlocksUsedBlockListHead
 
static struct GMemBlocksEmptyBlockListHead
 

Detailed Description

This file contains the functions need to manage allocation in goddard's heap.

However, the actual, useable allocation functions are gd_malloc(), gd_malloc_perm(), and gd_malloc_temp(), as well as gd_free(). This file is for managing the underlying memory block lists.

Function Documentation

◆ empty_mem_block()

void empty_mem_block ( struct GMemBlock block)

Empty a GMemBlock into a default state.

This empty block doesn't point to any data, nor does it have any size. The block is removed from whatever list is was in, and is added to the empty block list.

◆ gd_add_mem_to_heap()

struct GMemBlock* gd_add_mem_to_heap ( u32  size,
u32  addr,
u8  permanence 
)

Add memory of size at addr to the goddard heap for later allocation.

Returns
GMemBlock that contains info about the new heap memory

◆ gd_free_mem()

u32 gd_free_mem ( void ptr)

Free memory allocated on the goddard heap.

Parameters
ptrpointer to heap allocated memory
Returns
size of memory freed
Return values
0ptr did not point to a valid memory block

◆ gd_request_mem()

void* gd_request_mem ( u32  size,
u8  permanence 
)

Request a pointer to goddard heap memory of at least size and of the same permanence.

Returns
pointer to heap
Return values
NULLcould not fulfill the request

◆ init_mem_block_lists()

void init_mem_block_lists ( void  )

NULL the various GMemBlock list heads.

◆ into_free_memblock()

struct GMemBlock * into_free_memblock ( struct GMemBlock block)

Transform a GMemBlock into a free block that points to memory available for allocation.

Returns
pointer to the free GMemBlock

◆ make_mem_block()

struct GMemBlock * make_mem_block ( u32  blockType,
u8  permFlag 
)

Allocate a new GMemBlock structure of the given type and permanence.

It does not assign any heap space to the new block.

Parameters
blockTypeeither G_MEM_BLOCK_FREE or G_MEM_BLOCK_USED
permFlagsome sort of permanence value, where setting one the upper four bits imply a permanent block, while setting one the lower four bits imply a temporary block
Returns
a pointer to the new GMemBlock

◆ mem_stats()

void mem_stats ( void  )

Print summary information about all used, free, and empty GMemBlocks.

◆ print_list_stats()

u32 print_list_stats ( struct GMemBlock block,
s32  printBlockInfo,
s32  permanence 
)

Print information (size, entries) about the GMemBlock list.

It can print information for individual blocks as well as summary info for the entry list.

Parameters
blockGMemBlock to start reading the list
printBlockInfoIf TRUE, print information about every block in the list
permanenceLimit info printed to blocks with this permanence
Returns
number of entries

Variable Documentation

◆ sEmptyBlockListHead

struct GMemBlock* sEmptyBlockListHead
static

◆ sFreeBlockListHead

struct GMemBlock* sFreeBlockListHead
static

◆ sUsedBlockListHead

struct GMemBlock* sUsedBlockListHead
static