I've experimented some more and abbreviated the program:
Qt Code:
#include<QVector> struct myStruc { int array[3000*2000]; }; int main(int , char* []) { printf("hello\n"); fflush(stdout); sleep(1); QVector<myStruc> myVector; myStruc currentStruc; myVector.push_back(currentStruc); }To copy to clipboard, switch view to plain text mode
For array-sizes upto 3000*232 (=2.8MB), the above program works as expected.
For array-sizes between 3000*233 and 3000*698, it prints "hello" and then segfaults.
For array-sizes 3000*699 (=8.4MB) and up, it segfaults immediately, without even printing "hello".
Adding a QApplication object did not help.
Tested with gcc 4.3.2 on Ubuntu 8.10 using Qt-4.5.0-beta1.
Sheng, you've found the struct-of-death!![]()
Qt Code:
#include <stdio.h> #include <unistd.h> struct myStruc { int array[3000*2000]; }; void foo(const myStruc &v) { printf("%d\n", v.array[1]); } int main(int , char* []) { printf("hello\n"); fflush(stdout); sleep(1); myStruc currentStruc; foo(currentStruc); }To copy to clipboard, switch view to plain text mode
The above also crashes without printing hello, and now there isn't any Qt code left! Seems like a compiler or OS problem.
Last edited by drhex; 25th February 2009 at 21:36.
Qt Code:
#include <stdio.h> #include <sys/resource.h> int main(int , char *[]) { struct rlimit rlim; getrlimit(RLIMIT_STACK, &rlim); printf("max stack size=%d bytes\n", (int)rlim.rlim_cur); }To copy to clipboard, switch view to plain text mode
This prints
max stack size=8388608 bytes
on my machine. One learns something every day!
Bookmarks