Hello,
I’m seeking some clarity regarding the memory storage of application code and static libraries.
I understand the basic memory layout in terms of the code (text) segment, data segment, heap, and stack:
• Code Segment (Text Segment): Typically stores the compiled program code.
• Data Segment: Stores global and static variables.
• Heap: Dynamically allocated memory during runtime.
• Stack: Stores local variables and function call information.
However, I’ve come across some conflicting information:
1. Official Documentation: In an illustration from Apple’s official documentation, it appeared as though application code might be stored in the heap. This seemed unusual given my understanding that compiled code is generally stored in the code segment.
2. Blog Posts: Several blogs mention that the source code for static libraries is stored in the heap. This also contradicts my understanding since static libraries, after being linked, should be part of the application’s executable code, thus residing in the code segment.
Given these points, my understanding is that:
• Application Code: After compilation, the executable code should be stored in the code segment.
• Static Libraries: Once linked, the code from static libraries should also be part of the code segment.
Could you please clarify:
• Where exactly is the application code stored in memory?
• Is the claim that static libraries’ source code is stored in the heap correct, or is it a misunderstanding?
Thank you!