What is the Stack and Heap size of my Qt/C++ project?
-
wrote on 2 Aug 2018, 08:04 last edited by
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:) -
wrote on 2 Aug 2018, 08:35 last edited by VRonin 8 Feb 2018, 10:11
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); }
-
wrote on 2 Aug 2018, 09:58 last edited by
@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?:
#include <windows.h>
Hi,
Where is windows.h?! QT could not find it?...
Regards,
Mucip:)wrote on 2 Aug 2018, 10:01 last edited by@Mucip said in What is the Stack and Heap size of my Qt/C++ project?:
Where is windows.h?!
Should be part of the windows compiler. What are you using?
-
wrote on 2 Aug 2018, 10:04 last edited by
@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:) -
@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:) -
wrote on 2 Aug 2018, 10:07 last edited by VRonin 8 Feb 2018, 10:08
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(); }
-
wrote on 2 Aug 2018, 10:13 last edited by
@JonB said in What is the Stack and Heap size of my Qt/C++ project?:
You're in a severe mess if your MSVC doesn't have/find windows.h!
Hi,
I guess so...
Shoul I install win 10 SDK???Regards,
Mucip:) -
wrote on 2 Aug 2018, 10:35 last edited by
@JonB said in What is the Stack and Heap size of my Qt/C++ project?:
You're in a severe mess if your MSVC doesn't have/find windows.h!
Hi,
My situaiton like below...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(); }
wrote on 2 Aug 2018, 10:43 last edited by Mucip 8 Feb 2018, 10:54@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:)wrote on 2 Aug 2018, 11:54 last edited by@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
2/13