C、 大指针数组分配(linux 64位)
C, Large pointer array allocation (linux 64 bit)
我分配了2500000000个这样的单位:
struct test
{
public:
test();
void insert(unsigned int var1, unsigned int var2, unsigned long var3);
bool isEmpty() const;
unsigned char * data;
};
test::test()
{
data = NULL;
}
bool test::isEmpty() const
{
return (data == NULL);
}
unsigned long index = 25000000000;
像这样:
test *something = new (nothrow) test[index];
if (!something)
{
cout << "Error allocating memory for [something]" << endl;
return ;
}
cout << "DONE !" << endl;
则i甚至将其CCD_ 2的CCD_。
unsigned long j=0;
while (j<index)
{
something[j].data = NULL;
j++;
}
这一切都很好,除了当我迭代某物[]时,比如:
test *chk;
unsigned long empty = 0;
unsigned long not_empty = 0;
unsigned long i=0;
for (i=0; i< index; i++ )
{
chk = &something[i];
if (!chk->isEmpty())
{
not_empty++;
} else
empty++;
}
cout << "Empty [" << empty << "]" << endl;
cout << "Not Empty [" << not_empty << "]" << endl;
cout << "Total [" << empty + not_empty << "]" << endl;
(上次更新)
原来是硬件问题——内存。一些棍子不能与其他棍子一起正常工作。感谢大家的建议,太糟糕的硬件路径不在答案o/中
(更新)
我得到了一定数量的初始化元素,这些元素不是NULL(not_empty)。仍然不知道为什么。当然,empty+not_empty=索引。
如果我在构造函数中注释掉data = NULL;
,如果我在分配数组后立即循环数组,我会得到正确的空/非空数。但在强制指针为NULL后,在再次循环数组后,我仍然会得到相同的常量非空值。
我还使用malloc()将其修改为普通指针,这并没有什么不同,只是这是我第一次注意到指针是正确的(空的),直到我设置了它们。
我用较小的[指数]值(550000000)做了一些测试,但我无法复制这种行为。
我使用谷歌的ltcmalloc和分配的内存大小建议,它使用的是正确的[索引]大小;
与其写2500000000,不如写2500000000ul。我怀疑你的数字变成了32位整数,因此j<2500000000始终为真,因为int(2500000000)=-76980376。
相关文章:
- Qt Creator在linux mint 64位中找不到CMAKE_CXX_COMPILER编译器
- 在 64 位 Linux armv8 计算机上编译 32 位二进制文件时遇到问题
- 旧的 32 位 Linux 程序最终如何调用 64 位库
- 使用Solaris 64位或Linux 32位到Linux 64位的内存映射文件
- 试用版代码在 Windows 上的 32 位运行速度比在 Linux 上的 64 位快 2 倍
- 如何在 64 位 Linux Mint 上构建最小的静态 Qt 5.2 32 位库
- 尝试在Linux Mint 17.1 64位上"make" C++项目时从cstdlib和类似内容编译错误(未声明/不是类型)
- 32位和64位Linux机器中4字节类型之间的差异
- linux上64位体系结构的JNI库名称
- 64 位 Linux 计算机上的"fftw_malloc"段错误
- Linux、C++、Kdevelop、gcc、64位应用程序的升级难题
- 在 32 位 Linux 机器中生成的预处理器指令列表与为 64 位 Linux 机器生成的预处理器指令列表之间是否有区
- 检测 Linux 下的 32 位进程是否在 64 位环境中运行
- C、 大指针数组分配(linux 64位)
- bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误
- 如何为C++代码制作64共享64位linux兼容库(*.so)
- Linux环境下构建32位和64位应用程序(C++)
- g++4.9清理了linux(ubuntu 12.04 64位)上带有cin解析布尔值的漏洞
- 在64位打开的suse Linux上构建32exe给出链接错误
- 在Win7 64位上因未处理的首次机会异常而崩溃(在XP 32位、Linux 64位上没有问题)