What is the Stack and Heap size of my Qt/C++ project?
-
Hi,
How can I get information stack and heap size of my program which is written in Qt/C++?
I want to know memory usage of my program. So I can do something in case of memory overload!I see there is "size" command in Linux but I can not find equvielent in windows unfortunatelly! Maybe Qt has something to get this information?
Regards,
Mucip:) -
It's platform dependant. on Windows you can use:
double getUsedMemoryMB() { PROCESS_MEMORY_COUNTERS pmc; GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); return static_cast<double>(pmc.WorkingSetSize) / static_cast<double>(1024 * 1024); }
-
@VRonin said in What is the Stack and Heap size of my Qt/C++ project?:
#include <windows.h>
Hi,
Where is windows.h?! QT could not find it?...
Regards,
Mucip:) -
@VRonin said in What is the Stack and Heap size of my Qt/C++ project?:
Should be part of the windows compiler. What are you using?
Hi,
Win10 , QT Creator 4.7.0, QT 5.11.1 (MSVC 2015, 32 bit)Regards,
Mucip:) -
Working example compiled with MSVC: http://rextester.com/HCD11597
#include <iostream> #include <windows.h> #include <psapi.h> double getUsedMemoryMB() { PROCESS_MEMORY_COUNTERS pmc; GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); return static_cast<double>(pmc.WorkingSetSize) / static_cast<double>(1024 * 1024); } int main() { std::cout << getUsedMemoryMB(); }
-
Working example compiled with MSVC: http://rextester.com/HCD11597
#include <iostream> #include <windows.h> #include <psapi.h> double getUsedMemoryMB() { PROCESS_MEMORY_COUNTERS pmc; GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); return static_cast<double>(pmc.WorkingSetSize) / static_cast<double>(1024 * 1024); } int main() { std::cout << getUsedMemoryMB(); }
@VRonin said in What is the Stack and Heap size of my Qt/C++ project?:
#include <psapi.h>
Hi,
Finally I got it... Calital letter problem. It must be:#include "Windows.h"
#include "Psapi.h"Is returning number STACK or HEAP?... And what is the limit?...
Regards,
Mucip:) -
@VRonin said in What is the Stack and Heap size of my Qt/C++ project?:
#include <psapi.h>
Hi,
Finally I got it... Calital letter problem. It must be:#include "Windows.h"
#include "Psapi.h"Is returning number STACK or HEAP?... And what is the limit?...
Regards,
Mucip:) -
@VRonin said in What is the Stack and Heap size of my Qt/C++ project?:
#include <psapi.h>
Hi,
Finally I got it... Calital letter problem. It must be:#include "Windows.h"
#include "Psapi.h"Is returning number STACK or HEAP?... And what is the limit?...
Regards,
Mucip:)@Mucip said in What is the Stack and Heap size of my Qt/C++ project?:
Is returning number STACK or HEAP?
It's the sum of both
And what is the limit?
for 64bit systems the limit is just the hardware (how much RAM you have) for 32bit systems is the lower of the hardware memory and 4GB
-
@Mucip said in What is the Stack and Heap size of my Qt/C++ project?:
Is returning number STACK or HEAP?
It's the sum of both
And what is the limit?
for 64bit systems the limit is just the hardware (how much RAM you have) for 32bit systems is the lower of the hardware memory and 4GB