pavel-kirienko / o1heap

Constant-complexity deterministic memory allocator (heap) for hard real-time high-integrity embedded systems. There is very little activity because the project is finished and does not require further changes.
MIT License
245 stars 26 forks source link

provide an error code out argument for o1heapInit #17

Open thirtytwobits opened 1 year ago

thirtytwobits commented 1 year ago
int error_code = O1HEAP_NO_ERROR;
O1HeapInstance* h = o1heapInit(my_buffer, my_buffer_size, &error_code);

if (error_code == O1HEAP_ERR_BASE_TOO_SMALL)
{
    throw my_buffer_too_small_exception();
}

etc.

pavel-kirienko commented 1 year ago

There are no other error cases so having an error code will add no new information to the user.

pavel-kirienko commented 1 year ago

I take that back. There are two error cases: bad alignment and the arena being too small. Does this justify the existence of a separate argument?

thirtytwobits commented 1 year ago

I'm struggling to figure out what I'm doing wrong right now so...yes?

pavel-kirienko commented 1 year ago

Can I name the error code argument after you?

thirtytwobits commented 1 year ago

yes

thirtytwobits commented 1 year ago

perhaps if you provided a way to query the required minimum size then you can document that the failure is either that or that the pointer was not aligned per O1HEAP_ALIGNMENT.