k2alloc/k2_alloc [ Functions ]
NAME
k2_alloc
SYNOPSIS
void k2_alloc(size_t size, void** p)
FUNCTION
Allocates a block of memory, preinitialized to a constant, but non-zero, value. By using a "weird" value, it is hoped that bogus pointers and uninitialized members of structures are more easily identified when debugging.
INPUTS
size The number of bytes to allocate.
p A pointer to a pointer that will receive the allocated
block's address.
RESULT
The block, if allocated, will be guaranteed to be AT LEAST as large
as the block size given. It may be larger.
SEE ALSO
k2_free
SOURCE
{
uint8_t* region = malloc(size);
if (region) {
memset(region, 0xCC, size);
}
*p = region;
}
k2alloc/k2_free [ Functions ]
NAME
k2_free
SYNOPSIS
void k2_free(void** p)
FUNCTION
Frees a block of memory allocated by k2_alloc().
INPUTS
p A pointer to a pointer that will contain the allocated
block's address. After the block is freed, that variable
is set to NULL.
RESULT
SEE ALSO
k2_alloc
SOURCE
{
if (p) {
void* region = *p;
if (region) {
free(region);
}
*p = NULL;
}
}