Shouldn't an error code or NULL be returned if malloc or realloc fails?
andy5995 opened this issue · comments
It's kind of a design choice. There's a strong argument for "if you don't have enough RAM available to malloc, then there's not much you can do besides exit the program".
Additionally, as a fun fact, on many OSes like Linux, malloc
will NEVER return NULL
! They will happily reserve more virtual address space than they can possibly provide RAM for, and will simply crash later when you try to actually use the memory by reading or writing it.
Additionally, as a fun fact, on many OSes like Linux,
malloc
will NEVER returnNULL
! They will happily reserve more virtual address space than they can possibly provide RAM for, and will simply crash later when you try to actually use the memory by reading or writing it.
I see. Thanks for the explanation.