我在 Mac os x (10.7) 上遇到了 HDF5 的一些问题。经过一些测试,我确认 POSIX 写入似乎存在缓冲区大小超过 2gb 的问题。我编写了一个测试程序来演示这个问题:
#define _FILE_OFFSET_BITS 64
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
void writePosix(const int64_t arraySize, const char* name) {
int fd = open(name, O_WRONLY | O_CREAT);
if (fd != -1) {
double *array = new double [arraySize];
double start = 0.0;
for (int64_t i=0;i<arraySize;++i) {
array[i] = start;
start += 0.001;
}
ssize_t result = write(fd, array, (int64_t)(sizeof(double))*arraySize);
printf("results for array size %lld = %ld\n", arraySize, result);
close(fd);
} else {
printf("file error");
}
}
int main(int argc, char *argv[]) {
writePosix(268435455, "/Users/tpav/testfolder/lessthan2gb");
writePosix(268435456, "/Users/tpav/testfolder/equal2gb");
}
输出:
results for array size 268435455 = 2147483640
results for array size 268435456 = -1
如您所见,我什至尝试定义文件偏移量。对此我有什么可以做的,还是我应该开始寻找一种解决方法,以编写 2gb+ 块的方式?