tea_alloc
Signature
void* tea_alloc(tea_State* T, size_t size);Description
Allocates a raw block of size bytes using the state’s allocator. The returned pointer is not initialized and may be NULL if the allocation fails.
If size is zero, the behavior is allocator-dependent; prefer to avoid zero-size allocations.
Parameters
T- Teascript state
size- Number of bytes to allocate
Returns
Pointer to the newly allocated block, or NULL on failure.
Example
char* buf = (char*)tea_alloc(T, 256);
if(buf)
{
memcpy(buf, "hello", 6);
/* ... use buf ... */
tea_free(T, buf);
}See also
tea_realloc
Signature
void* tea_realloc(tea_State* T, void* p, size_t size);Description
Resizes the block at p to size bytes. If p is NULL, this behaves like tea_alloc. If size is zero, the block is freed and NULL may be returned. Otherwise the block is grown or shrunk, preserving as much of the existing contents as possible, and the (possibly new) pointer is returned.
Because the block may move, always assign the result back to your pointer.
Parameters
T- Teascript state
p- Pointer to an existing block allocated by this state, or
NULL size- New size in bytes
Returns
Pointer to the resized block, or NULL on failure or when size is zero.
Example
char* buf = (char*)tea_alloc(T, 64);
buf = (char*)tea_realloc(T, buf, 128);
if(buf)
{
/* use enlarged buf */
tea_free(T, buf);
}tea_free
Signature
void tea_free(tea_State* T, void* p);Description
Frees the raw memory block at
p, which must have been allocated by this same state (via tea_alloc or tea_realloc). Passing NULL is a no-op. Passing any other pointer is undefined behavior.Parameters
T- Teascript state
p- Pointer to a block previously allocated by this state, or
NULL
Example
void* p = tea_alloc(T, 128);
/* ... */
tea_free(T, p);