Main Page   Modules   Alphabetical List   Data Structures   Data Fields  

RwMemoryFunctions Struct Reference
[Memory & File Interfaces]


Data Fields

void *(* rwmalloc )(size_t size, RwUInt32 hint)
void(* rwfree )(void *mem)
void *(* rwrealloc )(void *mem, size_t newSize, RwUInt32 hint)
void *(* rwcalloc )(size_t numObj, size_t sizeObj, RwUInt32 hint)

Detailed Description

This type represents the memory functions used by RenderWare. The application may override the default functions by passing a RwMemoryFunctions structure populated with a user defined functions to RwEngineInit().

All RenderWare Graphics memory-management functions that allocate memory take an additional RwUInt32 parameter which is a memory hint. The main purpose of the hints is to help improve memory management, such as preventing memory fragmentation. To use the memory hints, you should have provided your own memory-management function through the RwEngineInit() function. For example, you might want to have a separate memory heap just for the RwMatrix or RpGeometry objects, or a separate heap for all temporary allocations inside RenderWare Graphics. As always, memory-management is very specific to each application and has to be organized and tuned for each one.

A memory hint contains the following information: RwMemoryHintDuration, RwMemoryHintFlag and chunkID. ChunkID is the id of either the object for which a memory request came, or of the module a call for allocation belongs to. Refer to RwCorePluginID for a list of all object IDs and to RwEngine, RwCriterionCoreID and RwCriterionWorldID for a list of all module IDs. You can extend all of these fields using specific values for duration, object IDs, flags and create custom hints that can be passed to all the memory allocation calls you make. A tipical call to RwMalloc looks like:

RwMalloc(size, rwID_MATRIX | rwMEMHINTDUR_FUNCTION);

Note:
Note that once you override these function you will be responsible for aligning the memory properly. Memory alignment differs between the various platforms and it can also affect the application performance.
See also:
RwMemoryHintGetDuration, RwMemoryHintGetChunkID, RwMemoryHintGetFlags, RwEngineInit.


Field Documentation

void*(* rwcalloc)(size_t numObj, size_t sizeObj, RwUInt32 hint)
 

Allocates an array in memory with elements initialized to 0.

Parameters:
numObj  Non-zero number of elements.
sizeObj  Non-zero length in bytes of each element.
hint  A RwUInt32 value representing a memory hint.
Returns:
A void pointer to the allocated space, or NULL if there is insufficient memory available.

void(* rwfree)(void *mem)
 

Deallocates or frees a memory block.

Parameters:
mem  Previously allocated memory block to be freed. Shouldn't be NULL pointer.

void*(* rwmalloc)(size_t size, RwUInt32 hint)
 

Allocates memory blocks.

Parameters:
size  Number of bytes to allocate. Should be greater then zero.
hint  A RwUInt32 value representing a memory hint.
Returns:
A void pointer to the allocated space, or NULL if there is insufficient memory available.

void*(* rwrealloc)(void *mem, size_t newSize, RwUInt32 hint)
 

Reallocate memory blocks.

Parameters:
mem  Pointer to previously allocated memory block.
size  New size in bytes. Should be greater then zero.
hint  A RwUInt32 value representing a memory hint.
Returns:
A void pointer to the allocated space, or NULL if there is insufficient memory available.


Criterion Software © 1993-2004 Criterion Software Limited. All rights reserved. Built Thu Feb 12 13:46:48 2004. Send Feedback