Free () frees memory immediately

In my program, I use malloc to allocate large amounts of memory (several hundred mbs, in chunks, say 25 to 75 mb at a time), then I free some chunks and then reallocate some of them again. My question is if I am using free () to free memory, free the corresponding block of memory immediately, or just mark it for free. If this is just an indication to free it later, is there some standard C library function to force free it.

I really need to develop my program for portability between linux and vxworks. In Vxworks, in one library that I use (vsipl), I find that "free" is not released immediately upon call.

0


source to share


1 answer


The answer depends on malloc and free implementation. However, I can safely say that in almost any implementation, memory is not freed. Instead, it is returned to the pool where it can be reused by the process.



If you are using large blocks of memory, it is usually best to use the memory functions of the operating system and do your own memory management. However, it is not recommended to map pages in and out of memory.

0


source







All Articles