4

I have a problem with Qt Creator, or one of its components.

I have a program which needs lots of memory (about 4 GBytes) and I use calloc to allocate it. If I compile the C code with mingw/gcc (without using the Qt-framework) it works, but if I compile it within the Qt Creator (with the C code embedded in the Qt framework using C++), using the mingw/gcc toolchain, calloc returns a null-pointer.

I already searched and found the qt-pro option QMAKE_LFLAGS += -Wl,--large-address-aware, which worked for some cases (around 3.5GBytes), but if I go above 4GBytes, it only works with the C code compiled with gcc, not with Qt.

How can I allocate the needed amount of memory using calloc when compiling with Qt Creator?

HonkyTonk
  • 1,961
  • 11
  • 11
user1703919
  • 43
  • 1
  • 4
  • What platform are you using? Is it 64-bit or 32-bit? Do you build as a 64- or 32-bit application? – Some programmer dude Sep 27 '12 at 16:20
  • QT Creator(with gcc 32bit) runs on Win7, the raw-c-code(which works fine) was compiled with cygwins x86_64-w64-mingw32-gcc.exe (so i guess 32bit, too) – user1703919 Sep 27 '12 at 16:26
  • 32-bit can't access that much memory (most likely 2-3GB per virtual address space). You need to compile as 64-bit and run on 64-bit. – quantum Sep 27 '12 at 16:30
  • Ok, thanks, but why does it work with cygwins x86_64-w64-mingw32-gcc.exe? I thought that is 32-bit too. – user1703919 Sep 27 '12 at 16:32

1 Answers1

1

So your cigwin tool chain builds 64-bit applications for your. Possible size of memory, that can be allocated by 64-bit application is 264 bytes that far exceeds 4Gb. But Qt Creator (if you installed it from QtSDK and not reconfigured it manually) uses Qt's tool chain, that builds 32 bit applications. You theoretically can allocate 4Gb of memory by 32 bit application, but do not forget, that all libraries will be also loaded into this memory. In practice, you are possible to allocate about 3 Gb of memory and not in one continuous chunk.

You have 3 ways to solve your problem:

  • reconsider your algorithm. Do not allocate 4Gb of RAM, use smarter data structures, or use disk cache etc. I believe if your problem would actually require more then 4 GB of memory to solve, you wouldn't ask this question.

  • separate your Qt code from your C program. Then, you can still use 64-bit-target-compiler for C program and 32-bit-target-compiler for Qt/C++ part. You can communicate with your C program through any interprocess communication mechanism. (Actually standard input/output streams are often enough)

  • Move to 64 bit. I mean, use 64-bit-target-compiler for both C and C++ code. But it is not so simple, as one could think. You'll need to rebuild Qt in 64 bit mode. It is possible with some modules turned off and some code fixups (I've tried once), but Windows 64 bit officially not supported.

Community
  • 1
  • 1
Lol4t0
  • 12,444
  • 4
  • 29
  • 65
  • Thank you! First option is not possible and I already thought about your second suggestion, so I will try that. Awesome Community btw, was my first Question ;) – user1703919 Sep 27 '12 at 18:06