I have a function that uses calloc to allocate memory in my program. If it runs out of memory if gives an error message.
The function is as follows:
I am going to change the code to use new instead of calloc. The function calloc returns a null pointer if it cannot allocate memory. How do I know if "new" has run out of memory?Code:void *ckalloc(size_t bytes) { register void *ret; if ((ret = calloc(bytes, sizeof(char))) == NULL) { fatal("Out of memory\n"); } else { return ret; } return ret; }
Also is there a way in C++ using new to reallocate memory (similar to realloc)?
Thanks
Mark