I would like to know which pointer values are invalid so i would not have to allocate new memory just to mark special chunk states(Memory consumption is critical). So i could use them for special states like
I would suggest just using a struct that contains a pointer and an enum. But if for some reason that's inconvenient, just allocate some small structures and use their addresses just to indicate magic pointer values. (Of course, don't ever free them.)
You can also use the address of static objects. Like this:
static int chunk_not_loaded_i, chunk_empty_i, chunk_full_i;
void *chunk_not_loaded = &chunk_not_loaded_i;
void *chunk_full = &chunk_full_i;
if (some_chunk == chunk_not_loaded)
...
Assigning exact values to the pointer is quite unstable and error-prone. That way, your code would be tight to exact hardware architecture(s). For example, some platforms have 0x00000000 as absolutely valid address. So the fact that address is assigned or not is not related to numeric value of the pointer (at common case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With