Japanese
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
 Allocate array area
 MEM_Calloc
 2
 Free memory block
 MEM_Free
 3
 Memory reservation
 MEM_Malloc
 4
 Memory reallocation
 MEM_Realloc
 5


2.2 Function specifications


 one
View
table
 Title

function specification

 Function

Memory management area settings

 Function name

MEM_Init

 No

1

Format
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 set as the memory management area.
remarks
Use this function only once in your game before using MEM_Calloc, MEM_Malloc, MEM_Realloc, and MEM_Free. If used more than once, the contents of previously allocated memory cannot be guaranteed.

 one
View
table
 Title

function specification

 Function

Allocate array area

 Function name

MEM_Calloc

 No

2

Format
void *MEM_Calloc(Uint32 arg_num, Uint32 arg_size)
input
arg_num: Number of array elements
output
arg_size: number of bytes of array element
function value
If successful, returns a pointer to the allocated memo block. Returns NULL in case of error.
function
Allocates the number of bytes of array elements in the memory management area. The allocated memory block will be cleared to 0.

 one
View
table
 Title

function specification

 Function

Free memory block

 Function name

MEM_Free

 No

3

Format
voidMEM_Free(void *mem_ptr)
input
mem_ptr: Pointer to memory block
output
none
function value
none
function
The specified memory block will be freed. The memory blocks that can be specified are those secured by MEM_Calloc, MEM_Malloc, and MEM_Realloc.

 one
View
table
 Title

function specification

 Function

Secure memory block

 Function name

MEM_Malloc

 No

4

Format
void*MEM_Malloc(Uint32 mem_size)
input
mem_size: Requested memory block size (byte specification)
output
none
function value
If successful, returns a pointer to the allocated memory area. Returns NULL in case of error.
function
Allocates a memory block of the requested memory block size in the memory management area and returns its pointer. If the requested memory block size is 0, the function value returns NULL. It is not initialized to 0.

 one
View
table
 Title

function specification

 Function

Memory reallocation

 Function name

MEM_Realloc

 No

5

Format
void*MEM_Realloc(void *mem_ptr, Uint32 mem_size)
input
 mem_ptr
 : pointer to previous memory block
 mem_size
 : New memory block size (byte specification)
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 specified memory block to the new memory block size. With reallocation, the contents of the previous memory block are transferred to the new area.

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