|
Memory Manager
Detailed Description
F4 provides a custom memory manager that must be used by all engine C++ code. This manager provides two important functions:
- Pooled allocations. The component-based architecture chosen for F4 requires many, potentially small, memory allocations and deallocations. Using the standard C memory manager, this usage pattern tends to be slow, especially as memory becomes fragmented. The F4 memory manager helps counteract this by pooling same-sized allocations together into larger pages.
- Error checking. In debug builds, the memory manager helps detect common memory errors:
- memory leaks
- use of uninitialized memory
- use of deleted memory
- over- and under-writes (not yet implemented)
- allocator/deallocator mismatches
To help use this information, the manager provides a number of breakpoint functions that allow program execution to be stopped when a particular memory operation is performed. Finally, the manager prints a detailed usage report when the program exits.
Using the new memory manager is easy: include <Memory/memory.h> at the top of your file (more on this below), and then use the traditional C/C++ allocators as usual: new, delete, new[], delete[], malloc, calloc, and realloc.
Because <memory.h> tries to redefine the standard memory operators, it can conflict with other headers which try to do the same thing. Your best bet is to include <memory.h> last whenever possible. If necessary, you may include <Memory/undef.h>, which will remove the macros.
Function Documentation
| MEMORY_API void breakOnAllocation |
( |
unsigned |
num |
) |
|
|
|
|
Break program execution when a particular allocation is made. |
| MEMORY_API void breakOnDealloc |
( |
void * |
ptr |
) |
|
|
|
|
Break program execution when an allocation is released. |
| MEMORY_API void breakOnRealloc |
( |
void * |
ptr |
) |
|
|
|
|
Break program execution when an allocation is reallocated. |
| MEMORY_API void printMemoryReport |
( |
|
) |
|
|
|
|
Display a report of memory statistics and current allocations (debug builds only). Call setMemoryPrintFunc() before using this function. This function will be called automatically when the program exits. |
| MEMORY_API void setMemoryPrintFunc |
( |
void(* |
func)(const char *) |
) |
|
|
|
|
Specify a print function. The memory manager will call this function whenever it has a message to display. |
Flat Four Engine
Copyright (C) 2001 by 379, Inc.
|
This page generated by Doxygen
|
|