Memory utility
Ikarus utility functions, for memory management and manipulation.
Initialization
The best way to initialize all Ikarus functions is to call MEM_InitAll()
in the Init_Global()
initialization function.
Warning
If you want to use Ikarus in Gothic 1, it is best to define your own Init_Global()
function and call it from every world initialization function.
Implementation
Functions
MEM_Alloc
MEM_Alloc
Allocates a specified amount of memory and returns a pointer to the allocated memory area.
Danger
Gothic does not and cannot retain a reference to this memory area or release it, even when destroying the session. Therefore, memory should only be reserved under certain conditions:
- It is guaranteed to exist and can be released again with
MEM_Free
after loading a save game. - Gothic is aware of this memory area and independently releases it.
It might be possible to create new objects with this function and permanently integrate them into the object structure of Gothic. However, extreme caution is advised, as object structures cannot be used, and manual handling is required.
This function is well-suited for building small elements like list items and integrating them into existing lists. The memory allocated by this function is always initialized to zero.
var int amount
The amount of bytes to allocate
Return value
The function returns a pointer to the allocated memory area.
MEM_Realloc
MEM_Realloc
Allocates a memory area of size newsize
and returns a pointer to this memory area. The memory area from location ptr
is released.
If newsize >= oldsize
, the first oldsize
bytes from the old memory area are transferred to the new one. The additional memory is initialized with zero.
If newsize <= oldsize
, all bytes of the new memory area are initialized with the corresponding values of the old memory area.
This function is intended to create an allocated memory area enlarge or reduce. Existing data remains naturally way received.
var int ptr
The original pointer to the memory blockvar int oldsize
The size of the original memory blockvar int newsize
The size of the new memory block
Return value
The function returns a pointer to the modified memory area.
MEM_Free
MEM_Free
Releases an allocated memory area.
Danger
Great caution is advised, especially when attempting to destroy engine objects, as no destructors are called!
Releasing small things such as list elements can be done easily.
var int ptr
Pointer to the released memory block
MEM_Copy
MEM_Copy
Copies a specified number of words from the source address to the destination address.
var int src
The source address to copy fromvar int dst
The destination address to copy tovar int wordCount
The number of words to copy
MEM_CopyWords
MEM_CopyWords
Alias to MEM_Copy
. Copies a specified number of words from the source address to the destination address.
var int src
The source address to copy fromvar int dst
The destination address to copy tovar int wordCount
The number of words to copy
MEM_CopyBytes
MEM_CopyBytes
Copies a specified number of bytes from the source address to the destination address
var int src
The source address to copy fromvar int dst
The destination address to copy tovar int byteCount
The number of bytes to copy
MEM_Swap
MEM_Swap
Swaps a specified number of words between the source address and the destination address.
var int src
The source address to swap fromvar int dst
The destination address to swap tovar int wordCount
The number of words to swap
MEM_SwapWords
MEM_SwapWords
Alias to MEM_Swap
. Swaps a specified number of words between the source address and the destination address.
var int src
The source address to swap fromvar int dst
The destination address to swap tovar int wordCount
The number of words to swap
MEM_SwapBytes
MEM_SwapBytes
Swaps a specified number of bytes between the source address and the destination address.
var int src
The source address to swap fromvar int dst
The destination address to swap tovar int byteCount
The number of bytes to swap
MEM_Clear
MEM_Clear
Sets a specified number of bytes in memory to zero.
var int ptr
The memory address to start clearing fromvar int size
The number of bytes to clear
MEM_Compare
MEM_Compare
Compares a specified number of words between two memory blocks.
var int ptr0
The first memory block to comparevar int ptr1
The second memory block to comparevar int wordCount
The number of words to compare
Return value
The function returns TRUE
if the memory blocks are equal, FALSE
is returned otherwise.
MEM_CompareWords
MEM_CompareWords
Alias to MEM_Compare
. Compares a specified number of words between two memory blocks.
var int ptr0
The first memory block to comparevar int ptr1
The second memory block to comparevar int wordCount
The number of words to compare
Return value
The function returns TRUE
if the memory blocks are equal, FALSE
is returned otherwise.
MEM_CompareBytes
MEM_CompareBytes
Compares a specified number of bytes between two memory blocks.
var int ptr0
The first memory block to comparevar int ptr1
The second memory block to comparevar int wordCount
The number of bytes to compare
Return value
The function returns TRUE
if the memory blocks are equal, FALSE
is returned otherwise.