Search code examples
cmemorymemory-managementsystemmemset

How long does memory written with memset() stay in memory without calling free()?


On Linux.

Hi. I'm sure there are many factors involved where the OS simply garbage-dumps memory allocated with memset() without calling free(), but I was wondering if anyone has a good estimation on this? That's really all I want to know.

There is a functionality in linux called KSM that saves memory space by combining matching data. My question revolves around detecting if KSM is working or not by checking the write time of the data. I have already successfully tested this on a machine while running everything in one program. Now I want to upload to memory, close the program, then open another program and test for memory duplication.

Thanks!

-Taylor


Solution

    • memset does not allocate memory, malloc does
    • the memory is not freed until a free call or the process terminates
    • there is no abstract machine in C, that the design principle of the language