Qt Creator - calloc失败,内存很大 [英] Qt Creator - calloc fails with large memory

查看:326
本文介绍了Qt Creator - calloc失败,内存很大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,Qt Creator或其中的一个组件。

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

我有一个程序需要大量的内存(大约4 GBytes),我使用calloc分配。如果我用mingw / gcc(不使用Qt框架)编译C代码它的工作原理,但如果我在Qt Creator(使用C ++嵌入在C框架中的C代码)编译它,使用mingw / gcc工具链,calloc返回一个空指针。

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.

我已经搜索,发现了qt-pro选项 QMAKE_LFLAGS + = -Wl, - large- -aware ,在某些情况下(大约3.5GBytes)工作,但如果我超过4GBytes,它只适用于用gcc编译的C代码,而不是Qt。

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.

在使用Qt Creator进行编译时,如何使用calloc分配所需的内存量?

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

推荐答案

因此,您的 cigwin 工具链为您构建64位应用程序。可以由64位应用程序分配的可能的内存大小是2 64 字节,远远超过4Gb。但是Qt Creator(如果你从QtSDK安装它并且不手动重新配置它)使用Qt的工具链,构建32位应用程序。你理论上可以分配4Gb的内存由32位应用程序,但不要忘记,所有的库也将加载到这个内存。在实践中,您可以分配大约3 Gb的内存,而不是一个连续的块。

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.


  • 重新考虑您的算法。不要分配4Gb的RAM,使用更智能的数据结构或使用磁盘缓存等。我相信,如果你的问题实际上需要更多的4 GB内存来解决,你不会问这个问题。

  • 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.

将Qt代码与您的C程序分离。然后,你仍然可以使用64位目标编译器的C程序和32位目标编译器的Qt / C ++部分。您可以通过任何进程间通信机制与C程序通信。 (实际上,标准输入/输出流通常就足够了)

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)

移到64位。我的意思是,对于C和C ++代码使用64位目标编译器。但它不是那么简单,因为人们可以想。你需要在64位模式下重建Qt。这是可能的一些模块关闭和一些代码fixups(我试过一次),但 Windows 64位官方不支持

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.

这篇关于Qt Creator - calloc失败,内存很大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆