sys_malloc(long size);
sys_nxalloc(long size);
Allocates a contiguous memory area with the given size. This can be used to create arrays of dynamic size. A7.79
Parameters:
size - Size of the allocated memory area, in bytes.
Returns:
void* pointer to the allocated memory area, or NULL when the allocation failed. The area is cleared to zero at allocation.
Speed:
Medium (sys_malloc)
Fast (sys_nxalloc)
Remarks:
-
The sys_malloc function
is a somewhat safer variant of the C/C++ malloc function or new operator.
- Memory allocated with sys_malloc
adds to sys_memory, and
can be individually released with sys_free. Otherwise the engine automatically releases all sys_malloc memory areas on exit.
- If a marker was set with sys_marker, non-freed memory areas are indicated in the acklog.txt at engine exit. If a memory area was overwritten, it's also indicated in the acklog.txt with the marker "SYS" if no other marker was set.
- Memory allocated with sys_nxalloc is taken from the level cache,
which can be partially released
with level_free.
The engine automatically releases all sys_nxalloc memory areas on level_load. As long as the nexus is not exceeded, sys_nxalloc is faster than sys_malloc and works regardless of the available PC memory, but does not survive a level change.
- For allowing huge memory sizes, the size parameter is long, not var.
Example:
See ent_nextvertex.
See also:
sys_free, level_free, sizeof, sys_memory, nexus
► latest
version online