PDA

View Full Version : Qt 5 stack memory limit?



te777
31st October 2013, 16:15
I’m using Qt 5.1 32 bit for VS2012. My application has a class that gets instantaniated when I press a button on the main form. The class has large arrays. When I try to run the program, it crashes. When I decrease the array sizes by 10 to 1, for example, no problems. The large arrays are for data calculations, Here are the array sizes:

array1 [100000×4]
array2 [10000×5]
array3 [1000×6]
array4 [100×7]
array5 [50×8]

Will using the 64 bit Qt 5 solve my problem?

I have ported the same program from C# in Visual Studio 2013 compiled for 32 bit, and the code works fine there. I don’t know why Qt would be different.

I’m using Windows 7 SP1 64 bit with 8 GB ram.

Any help would be appreciated. Thanks in advance.

Lesiok
31st October 2013, 16:21
This is not a Qt problem but C++ compiler. Maybe this article (http://social.msdn.microsoft.com/Forums/vstudio/en-US/2a5b32b6-683b-4729-92d3-45ed7a89ef3f/stack-overflow-and-how-to-increase-the-stack-size) helps.

ChrisW67
31st October 2013, 20:17
We have no idea what size each of these objects in your array is. 400000 bytes is a very different beast to 400000 doubles (3.2MB) or 400000 10kbyte QPixmaps. We can only assume that they are stack allocated but that is also not specified. The default stack size limit in VC++ is 1MB from memory. The stack limit could be avoided by heap allocation but a 32 bit executable on Windows also has a 3 gigabyte absolute limit on the program memory space. It is also possible you do not have a size problem but an out-of-bounds problem that trashes the program stack causing whatever the unspecified error is.

It is possible that just using QVector or a similar container will avoid the problem without imposing manual memory management on you.

te777
1st November 2013, 00:25
I solved the problem by adding a line to my .pro file:

QMAKE_LFLAGS_WINDOWS += -Wl,--stack,32000000

for minGW 32 bit compiler

and

QMAKE_LFLAGS += /STACK:32000000

for msvc 32 bit compiler.

Runs lightening fast. Only adds 2 MB of memory in Task Manager.

Thanks for the replies.