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

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

问题描述

我有一个问题,Qt Creator的,或者它的组件之一。

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

我有一个计划,需要大量的内存(约4 GB的),我用释放calloc分配它。如果我编译C code使用MinGW / GCC(不使用Qt框架)它的工作原理,但如果我编译它的Qt Creator的范围内(用C ++嵌入Qt框架的C code)使用的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 + =轮候册, - 大地址意识,这工作有些情况下(约3.5GBytes) ,但如果我上面去4GBytes的,它只能与C code使用GCC编译,不会使用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.

我如何使用释放calloc分配的内存量需要用Qt Creator的编译时?

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位应用程序。您在理论上可通过32位应用程序分配的4Gb的内存,但不要忘记,所有的图书馆也将被加载到内存中。在实践中,你可以分配约3 G的内存,而不是在一个连续的数据块。

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的内存,使用更智能的数据结构,或使用磁盘缓存等。我相信,如果你的问题会的实际需要的更多然后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.

在C程序分开你的Qt code。然后,您仍然可以使用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位。我的意思是,使用64位目标编译器为C和C ++ code。但它不是那么简单,因为人们可以认为。你需要重建的Qt在64位模式。这是可能的一些模块关闭,一些code的修正(我试过一次),但的的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天全站免登陆