I am planning to create cross-platform library to provide access to system configuration information (installed hardware, model of CPU, etc...).
When looking for way to access total memory (by "total" I mean amount of memory installed in system, not memory available to system), I found some problems.
In Windows, this code provide correct value:
#include <Windows.h>
....
uint64_t memory;
GetPhysicallyInstalledSystemMemory(&memory);
In OS X, this code provide correct value:
#include <sys/sysctl.h>
...
size_t memorySize;
sysctlbyname("hw.memsize",nullptr,&memorySize,nullptr,0);
int64_t memory;
sysctlbyname("hw.memsize",(void*)&memory,&memorySize,nullptr,0);
In case of Linux(Ubuntu), common way to get memory information is to parse information from command "free" or file "/proc/meminfo". Problem is that these options provide memory usable to system, which is close but not the same as total memory (similar situation with Windows function "GlobalMemoryStatusEx").
Additionally, I plan to use only C or C++ API to gather required information and don't want to result to parsing text using File API.
I am aware of command dmidecode where I could just add memory in each installed memory bank, but beside the need to pars textual data, command requires root to run.
So main question, is there option as described here ? Maybe exists function that was added later in time and is not very popular ( For Windows, I found information about "GetPhysicallyInstalledSystemMemory" function much later, because it was introduced in Windows Vista and most examples use older "GlobalMemoryStatusEx").
EDITED:
Question is not duplicated as I describe specific problem with obtaining "total" memory as total memory installed in particular system. Also, I clearly specify requirements for possible solution using only C or C++ API available, not parsing results of command or text file like "/proc/meminfo" as other similar questions do not set such requirements.
EDITED_2:
Changes to reflect that both C and C++ API are applicable