I have looked over the API, but it confuses me. Take this for example:
void buflib_init(struct buflib_context *context, void *buf, size_t size);
and
void
buflib_init(struct buflib_context *ctx, void *buf, size_t size)
{
union buflib_data *bd_buf = buf;
/* Align on sizeof(buflib_data), to prevent unaligned access */
ALIGN_BUFFER(bd_buf, size, sizeof(union buflib_data));
size /= sizeof(union buflib_data);
/* The handle table is initialized with no entries */
ctx->handle_table = bd_buf + size;
ctx->last_handle = bd_buf + size;
ctx->first_free_handle = bd_buf + size - 1;
ctx->first_free_block = bd_buf;
ctx->buf_start = bd_buf;
/* A marker is needed for the end of allocated data, to make sure that it
* does not collide with the handle table, and to detect end-of-buffer.
*/
ctx->alloc_end = bd_buf;
ctx->compact = true;
}
From the source, I assume that I don't need to manually set up the buflib context structure, but what is the void pointer about? What do I set it to? Should I even set it?
Actually, the API kinda makes sense once I look over buflib.c, but it still doesn't explain everything.