(which I am assuming, but don't know for certain, is equal to the total virtual memory) |
Nope, sorry but it doesn't work that way. The addresses you see for your pointers aren't the absolute memory addresses in the machine. In addition to that, (on Windows for example) memory is partitioned into system memory and user space memory; so you could theoretically exhaust all of the allocatable memory in user space with your program and still have almost half of your RAM physically doing nothing. This allocation is done at boot time so you can't really do anything to shift it around arbitrarily to meet your goal.
My plan for achieving this is by using macros to determine the target computer, then including the correct headers and using the correct functions based on that. |
But at the same time...
... at run-time (not compile-time). |
I looks like you mentally changed tracks half way through writing this. Which approach did you decide on?
What I am asking from you is that if you have any special information about this on a type of computer that has not yet been listed in the comments, then please list your way of getting the max value of the pointer and which macrois will identify the computer. |
Even if your method weren't flawed from the start, you have to know that you doing this the hard way. P.S. macros are destroyed at compile time, they are pretty much just find and replace statements that you tell the compiler to sort out.
- Windows: GetPhysicallyInstalledSystemMemory():
https://msdn.microsoft.com/en-us/library/windows/desktop/cc300158(v=vs.85).aspx
- POSIX: sysinfo():
http://man7.org/linux/man-pages/man2/sysinfo.2.html
You'll have to ask someone else about how to do this on a Mac. Objective-C is for masochists and to build your OS's API around it proves that Apple is a sadistic corporation.
EDIT: By the way, given your list of objectives:
- Simplistic task
- Run time determination of host platform
- OS agnostic with out an intermediate library such as Boost ASIO
Believe it or not,
Java, or one of its subsidiaries, will be the right tool for this task, not C or C++.