Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are out-of-memory handling strategies in C programming?

Tags:

People also ask

What are the types of memory in C?

C Memory ModelMemory ModelIn computing, a memory model describes the interactions of threads through memory and their shared use of the data.https://en.wikipedia.org › Memory_model_(programming)Memory model (programming) - Wikipedia The C runtime memory model can be divided in to three types; global/static memory, the heap, and the stack. These all share the RAM available on the microcontroller.

What is memory management in C programming?

Dynamic memory management in C programming language is performed using the malloc() , calloc() , realloc() , and free() functions. These four functions are defined in the <stdlib.h> C standard library header file. It uses the heap space of the system memory.

Why is memory management important in C?

Memory management requires that the programmer provides ways to dynamically allocate portions of memory to programs, when requested, and free it for reuse when it is no longer needed. In any advanced computer system, where more than a single process might be running at any given point in time, this is critical.


One strategy that I though of myself is allocating 5 megabytes of memory (or whatever number you feel necessary) at the program startup.

Then when at any point program's malloc() returns NULL, you free the 5 megabytes and call malloc() again, which will succeed and let the program continue running.

What do you think about this strategy?

And what other strategies do you know?

Thanks, Boda Cydo.