在Linux C ++应用程序寻找和阅读大文件 [英] Seeking and reading large files in a Linux C++ application

查看:202
本文介绍了在Linux C ++应用程序寻找和阅读大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到整数溢出使用标准的 FTELL 的和的 fseek的的G ++里面的选项,但我想我是错了,因为它似乎的 ftell64 fseek64 的不可用。我一直在寻找,许多网站似乎使用引用的 lseek的 off64_t 的数据类型,但我还没有找到参考的东西等于任何实例的 fseek的的。现在,我正在读的文件与在预期16GB + CSV文件至少两倍。

I am running into integer overflow using the standard ftell and fseek options inside of G++, but I guess I was mistaken because it seems that ftell64 and fseek64 are not available. I have been searching and many websites seem to reference using lseek with the off64_t datatype, but I have not found any examples referencing something equal to fseek. Right now the files that I am reading in are 16GB+ CSV files with the expectation of at least double that.

在没有任何外部库什么是实现相似的结构用的 fseek的/ FTELL 的一双最简单的方法是什么?我的应用程序现在使用作品的标准GCC / G ++库4.x版。

Without any external libraries what is the most straightforward method for achieving a similar structure as with the fseek/ftell pair? My application right now works using the standard GCC/G++ libraries for 4.x.

推荐答案

fseek64是一个C函数。以使其可你必须包括系统标头将或多或少fseek的定义是实际fseek64之前定义_FILE_OFFSET_BITS = 64。或者在编译参数做如
 GCC -D_FILE_OFFSET_BITS = 64 ......

fseek64 is a C function. To make it available you'll have to define _FILE_OFFSET_BITS=64 before including the system headers That will more or less define fseek to be actually fseek64. Or do it in the compiler arguments e.g. gcc -D_FILE_OFFSET_BITS=64 ....

http://www.suse.de/~aj/linux_lfs.html 有很大overviw在Linux上的大文件支持:

http://www.suse.de/~aj/linux_lfs.html has a great overviw of large file support on linux:


  • 编译与海湾合作委员会-D_FILE_OFFSET_BITS = 64的节目。这将迫使所有的文件访问调用使用64位的变体。几种类型也随之变化,例如off_t变得off64_t。这是很重要的,始终使用正确的类型和不使用例如整型不是off_t。为了与其他平台的可移植性,你应该使用在getconf LFS_CFLAGS将返回-D_FILE_OFFSET_BITS = 64在Linux平台上,但可能会在别的例如返回的东西Solaris操作系统。对于链接,你应该使用那些通过在getconf LFS_LDFLAGS报告的链接标志。在Linux系统中,你不需要特殊的链接标志。

  • 定义_LARGEFILE_SOURCE和_LARGEFILE64_SOURCE。有了这些定义可以使用LFS功能,如直接open64。

  • 使用O_LARGEFILE标志和开放的大文件进行操作。

这篇关于在Linux C ++应用程序寻找和阅读大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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