0

This is semi-theoretic question.

Can I specify the virtualization mode for memory (pure segmentation/segmentation+paging/just paging) while compiling for Windows (e.g., MSVS12 C++) and for Linux (e.g. g++)?

I have read all MSVS linker+compiler options, and found no point of control in there.

For g++ the manual is quite too complex for such question.

The source of this question is this - link

I know from theory and practice that these should either be possible or restricted by OS policy at some level cause core i7 supports all three modes I mentioned above.

Practical background:

The piece of code that created lots of data is here, function Init - and it exhausted my memory if I wanted to have over 2-3G primes on heap.

Community
  • 1
  • 1
sdd
  • 721
  • 9
  • 23
  • If I understand your question correctly, those things are set system wide during bootload, and no modern kernel will run without paging to allow userspace, access control, and paging. – Linuxios Aug 29 '14 at 16:25
  • If I understand your comment correctly, both win7 and, for example, ubuntu14.04 set their paging/segmentation options during bootload system-wide? If so, what are the defaults (if user has not tinkered with this aspects of OS)? As far as I understand, in win7 program heap is one of the segments. On what it depends whether it is paged or not? – sdd Aug 29 '14 at 17:14
  • I'm pretty sure that neither windows or linux can function at all without the granular control that paging offers them. Both use paging for access control even if swap is disabled. – Linuxios Aug 29 '14 at 17:19
  • @Linuxios, thx. I've read this theoretic Tanenbaum's "S.C.O." book and it is quite vague on applications. I guess, this three modes in practice do not have clear boundaries and some of them are used only for legacy code execution. – sdd Aug 31 '14 at 13:26

2 Answers2

1

Intel x86 CPUs always use some form segmentation that can't be turned off. In 64-bit mode code segmentation is limited, but it's still there. Paging is required for both Windows and Linux to work on Intel CPUs (though Linux doesn't use paging on certain other CPU architectures). Paging is also required to enable 64-bit mode on Intel CPUs.

So in other words on Windows and Linux the OS always uses segmentation and paging, and so do any applications run on them, though this is largely transparent. It's not possible to "compiled+linked for 'segmentation without paging'" as you said in the answer you linked. Maybe the book you referenced is referring to ancient 16-bit versions of Windows (3.1 or earlier) which could be run in a mode that supported 80286 CPUs which didn't have paging. Though even then that normally didn't make any difference in how you compiled and linked your applications.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • Hi! The practical background to my question is as follows: I have had written a C++ program some time ago, that created a VERY BIG (more than user-available 2-3G out of 4G physical) data structure on heap. I compiled it towards x86-64. And it crashed with some (sorry, don't remember the details) out-of-memory exception. Shouldn`t my heap mem segment be paged out while it was growing up? What I`m not getting? – sdd Aug 31 '14 at 13:19
  • The piece of code that created lots of data is here, function Init - https://github.com/ddsherstennikov/AscendingPrimeSequences/blob/master/Precomputed.cpp – sdd Aug 31 '14 at 13:45
  • You should post a new question about asking why your program crashes when allocating a large amount of memory. Try to reduce into an example program that crashes with the same error and include it in your question. Be sure to also include the exact error message, details about how you compiled it and what operating system you ran it on. – Ross Ridge Aug 31 '14 at 14:41
0

What you are describing is not a function of a compiler, or even a linker.

When you run your program, you get the memory model that is already running on the system. Your compiled code does not care abut the underlying memory mode.

However, your program itself can change the memory model IF it starts running in an unprotected processor mode.

user3344003
  • 20,574
  • 3
  • 26
  • 62