How to get the RAM memory size programmatically [duplicate] - c++

This question already has answers here:
Getting memory information with Qt
(3 answers)
How to get memory usage at runtime using C++?
(11 answers)
Closed 8 years ago.
I am looking for a way to retrieve the RAM memory size of my computer in C++ with Qt.
My primary target is Windows, if that would make things easier.

Related

std::vector clear or swap with new vector [duplicate]

This question already has answers here:
Does clearing a vector affect its capacity?
(4 answers)
C++ delete vector, objects, free memory
(7 answers)
Closed 3 years ago.
Sometimes I detect in different c++ projects code like this:
std::vector<DataClass> _dataVec;
...
std::vector<DataClass>().swap(_dataVec);
Is this code more effective than obvious and simple clear call
_dataVec.clear();
or these code samples have some kind of difference?
For what purpose I should prefer first variant?

How could I know how much CPU time is used by all threads? [duplicate]

This question already has answers here:
How to determine CPU and memory consumption from inside a process
(10 answers)
Closed 7 years ago.
I have a few threads in my program - run on Windows and write in C++.
How can I know in the end of the running how much CPU time is used by all or one of them?
You can use the GetThreadTimes function: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683237%28v=vs.85%29.aspx

How do I find the L2CacheSize, L3CacheSize from C++ on Windows7? [duplicate]

This question already has answers here:
C++ cache aware programming
(10 answers)
Closed 7 years ago.
I am profiling my code on various CPUs running Windows7 and my results so far suggest that I need to tune a buffer size proportional to the machine's L2CacheSize or L3CacheSize. Is there a way to obtain these parameters from C++?
You can use the GetLogicalProcessorInformation function to get that. It returns an array of SYSTEM_LOGICAL_PROCESSOR_INFORMATION structures which contain a CACHE_DESCRIPTOR structure, which provides the cache size information.

Get memory and CPU usage using PID? [duplicate]

This question already has answers here:
How to get memory usage under Windows in C++
(5 answers)
Closed 9 years ago.
Under windows, given a PID:
1) How to get the exact memory in bytes and
2) The exact CPU usage
consumed by that application right now?
See GetProcessMemoryInfo, and specifically the WorkingSetSize field of the out parameter.
GetProcessTimes will let you know how much time your process has spent altogether in user & kernel space. It's up to you to calculate percentages, or whatever you want out of it.

Work with File in windows [duplicate]

This question already has answers here:
How can we check if a file Exists or not using Win32 program?
(9 answers)
C++: Which is the best method of checking for file existence on windows platform [duplicate]
(11 answers)
Closed 9 years ago.
I need a function in c++ to check if a given path/filename exists on the computer.
Can anyone help me?
This could be another possibilty besides the ones from the comments
PathFileExists