Qt Creator - calloc with great memory

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

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

I already searched and found the qt-pro QMAKE_LFLAGS += -Wl,--large-address-aware , which worked in some cases (about 3.5 GB), but if I switch to 4 GB, it only works with C code compiled with gcc and not with Qt.

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

+4
source share
1 answer

So, your cigwin creates 64-bit applications for you. The possible memory size that can be allocated by a 64-bit application is 2 bytes sup <64>, which is much more than 4 GB. But Qt Creator (if you installed it from the QtSDK and did not reconfigure it manually) uses the Qt tool chain, which builds 32-bit applications. You can theoretically allocate 4 GB of memory with a 32-bit application, but do not forget that all libraries will also be loaded into this memory. In practice, you can allocate about 3 GB of memory, rather than one continuous piece.

You have 3 ways to solve your problem:

  • revise your algorithm. Do not allocate 4 GB of RAM, use more intelligent data structures, or use disk cache, etc. I believe that if your problem requires more than 4 GB of memory, you will not ask this question.

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

  • Move to 64 bit. I mean using a 64-bit target compiler for C and C ++ code. But it is not as easy as you might think. You will need to rebuild Qt in 64 bit mode. This is possible when you turn off some modules and some code fixes (I tried it once), but Windows 64 bit is not officially supported .

+1
source

Source: https://habr.com/ru/post/1436650/


All Articles