For example:
If I have a function named void Does_Stuff(int arg)
and call it in the main function, is void Does_Stuff loaded into memory ONLY when it is first called? Or is it loaded into memory during program initialization?
And after calling Does_Stuff in main, can I manually unload it from memory?
For reference the operating system I am running is Windows 7 and I am compiling with MinGW.
In simple terms (with the usual depends-on-various-platform-things caveat), the code for your normal, global C function is "loaded into memory" at the time the program is loaded. You cannot request that it be "unloaded".
That said, as Hans mentions in a comment, the OS at a lower level is in charge of what bits of stuff are important enough to be present in physical RAM, and may choose to "page out" memory that isn't being used frequently. This isn't per-function, and has no knowledge of the structure of your code. So in that sense the function's code may happen at various times exist in actual RAM or not. But this is a level below the application's execution, where a C function is always "present and available".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With