Reputation: 21562
As someone with a cursory understanding of executable file formats, I found the following #pragma
directives in MSDN's documentation very interesting:
What exactly is the advantage of putting certain variables and function bodies in a different .section
in the PE/OBJ file than the default sections for such things?
Upvotes: 0
Views: 136
Reputation: 8661
Changing segments is mostly used in embedded software to map some data to various physical storage areas. For instance you might want some of your variables to be saved in an EEPROM, in which case you could define a special segment to be mapped on EEPROM addresses at link time.
For WIN32 executables it is of limited use. You might want to use it to share a bit of memory between various instances of a process, though you'd better know what you're doing if you try to tamper with memory mapping.
Upvotes: 1
Reputation: 155578
Well, traditionally literal are constant (e.g. static const char* const = "hello world";
) in-part because they're located in the const_seg
area, if they were located in the data_seg
or bss_seg
they could be mutable (though not resizable-in-place for obvious reasons).
Another reason (in the same vein) might be to pre-initialize a complex data structure at compile-time yet allow it to be manipulated at runtime, for example a large hashtable of known-values, though this would require compiler-support.
Upvotes: 1