gpt4 book ai didi

c++ - 为什么malloc总是分配内存失败(大约9GB,但我有16GB物理内存)?

转载 作者:行者123 更新时间:2023-11-30 20:54:38 25 4
gpt4 key购买 nike

我相信我的 ubuntu(64 位应用程序)中有足够的内存(16G)用于此分配。但它仍然总是返回 NULL。

以下是我运行 free 命令的内存信息。

             total       used       free     shared    buffers     cached
Mem: 16376100 3295024 13081076 41936 88852 1073808
-/+ buffers/cache: 2132364 14243736
Swap: 15998972 0 15998972

屏幕截图:

http://i.stack.imgur.com/QjW27.png

最佳答案

根据评论,我明白了。这是因为当我计算内存大小时,总和溢出了。

另一种情况是我使用int n_dataset = 2453688725;,它溢出了,n_dataset将是负数。

关于c++ - 为什么malloc总是分配内存失败(大约9GB,但我有16GB物理内存)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38404802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com