PROGRAMMER'S GUIDEMemory management library
Back | ■
Memory management library

2. reference


2.1 Function list


 function
 Function name
 number
 Memory management area definition
 MEM_Init
 1
 Reserve array area
 MEM_Calloc
 2
 Memory block release
 MEM_Free
 3
 Memory allocation
 MEM_Malloc
 Four
 Memory reallocation
 MEM_Realloc
 Five


2.2 Function specifications


 List
 Title

Function specifications

 Function

Memory management area setting

 Function Name

MEM_Init

 No

1

Form
void MEM_Init (Uint32 top_address, Uint32 mem_size)
input
 top_address
 : Memory management area start address
 mem_size
 : Memory management area size (byte specification)
output
none
Function value
none
function
Set the memory management area used by MEM_Calloc, MEM_Malloc, MEM_Realloc, and MEM_Free. The area corresponding to the memory size from the start address of the specified memory is used as the memory management area.
remarks
Use this function only once in the game before using MEM_Calloc, MEM_Malloc, MEM_Realloc, MEM_Free. If you use it more than once, the contents of the previously allocated memory cannot be guaranteed.

 List
 Title

Function specifications

 Function

Reserve array area

 Function Name

MEM_Calloc

 No

2

Form
void * MEM_Calloc (Uint32 arg_num, Uint32 arg_size)
input
arg_num: Number of array elements
output
arg_size: number of bytes in the array element
Function value
If it ends normally, it returns a pointer to the reserved memo block. Returns NULL in case of error.
function
Allocate the number of bytes of the array element in the memory management area for the number of array elements. The allocated memory block is cleared to 0.

 List
 Title

Function specifications

 Function

Memory block release

 Function Name

MEM_Free

 No

3

Form
voidMEM_Free (void * mem_ptr)
input
mem_ptr: pointer to memory block
output
none
Function value
none
function
The specified memory block is released. The memory blocks that can be specified are those allocated by MEM_Calloc, MEM_Malloc, and MEM_Realloc.

 List
 Title

Function specifications

 Function

Secure memory block

 Function Name

MEM_Malloc

 No

Four

Form
void * MEM_Malloc (Uint32 mem_size)
input
mem_size: Request memory block size (byte specified)
output
none
Function value
If it ends normally, it returns a pointer to the allocated memory area. Returns NULL in case of error.
function
Allocates a memory block for the requested memory block size in the memory management area and returns a pointer to it. If the requested memory block size is 0, NULL is returned for the function value. Initialization with 0 is not performed.

 List
 Title

Function specifications

 Function

Memory reallocation

 Function Name

MEM_Realloc

 No

Five

Form
void * MEM_Realloc (void * mem_ptr, Uint32 mem_size)
input
 mem_ptr
 : Pointer to previous memory block
 mem_size
 : New memory block size (byte specified)
output
none
Function value
If successful, returns a pointer to the reallocated memory. Returns NULL in case of error.
function
Changes the memory block size of the pointer to the previous memory block to the new memory block size. Reallocation transfers the contents of the old memory block to the new area.

Back | ■
PROGRAMMER'S GUIDEMemory management library
Copyright SEGA ENTERPRISES, LTD., 1997