Contexts#
-
type UNIT_Context#
Container type for all of UNIT’s state. This structure has no public fields, but its size is available publicly (allowing for allocation on the stack).
-
UNIT_Status UNIT_Context_Init(UNIT_Context *context)#
Initialize a context. On success,
UNIT_Context_Clear()must be called later to free memory allocated by this function.- Parameters:
context – A pointer to a context. Memory at this location will be overwritten.
- Returns:
Indicator whether the call was successful. See
UNIT_FAILED.
Example# UNIT_Context context; if (UNIT_FAILED(UNIT_Context_Init(&context))) { return -1; } // Must call UNIT_Context_Clear() later.
Quirk
If this function fails, there will not be any error indicator set, because there’s no context to store it on.
-
UNIT_Context *UNIT_Context_New(void)#
Create a new context. On success,
UNIT_Context_Free()must be called later to free memory allocated by this function.- Returns:
A heap-allocated pointer to the context, or
NULLif an allocation failed. If non-NULL, must be deallocated usingUNIT_Context_Free().
Example# UNIT_Context *context = UNIT_Context_New(); if (context == NULL) { return -1; } // Must call UNIT_Context_Free() later.
Quirk
If this function fails, there will not be any error indicator set, because there’s no context to store it on.
-
void UNIT_Context_Clear(UNIT_Context *context)#
Free memory allocated by
UNIT_Context_Init().- Parameters:
context – The context to clear.
-
void UNIT_Context_Free(UNIT_Context *context)#
Free memory allocated by
UNIT_Context_New(). This will also callUNIT_Context_Clear(). Safe to call withNULL.- Parameters:
context – The context to free, or
NULL.