Solved 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:) -
@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?
-
@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:) -
@Mucip
You're in a severe mess if your MSVC doesn't have/findwindows.h
! -
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(); }
-
@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:) -
@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:) -
@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 Windows filing system is case-insensitive, so no idea why you say you require capitals.
-
@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
-
Dear @VRonin
Well, what about the 64K STACK limit I remember from old times?...Regards,
Mucip:)