c++에서 큰 파일을 다루기

urmajest의 이미지

안녕하세요

C++을 사용해서 65GBytes정도되는 큰 파일을 다루려고 하는데요..

예를 들어..

        dumpFile.open("파일이름" , ios::in | ios::binary);
        dumpFile.seekg(0, ios::end);
        cout << "File Size = " << dumpFile.tellg() << "Bytes" << endl;

와 같이 파일 사이즈를 알아낼 때 보통 seekg와 tellg를 이용하곤 했는데,

파일 사이즈가 너무 커지니 dumpFile.tellg()가 항상 -1이 나오게 되네요.

큰 파일을 C++에서 쉽게 다룰 수 있는 방법이 없을까요? :)

RavenDarkmoon의 이미지

Windows에선 SetFilePointer/SetFilePointerEx를 이용해 64bit 어드레싱이 가능한데 Linux에서도 지원하는 System Call이 있지 않을까요?

byung82의 이미지

흠..

gcc도 2G이상의 파일을 다 룰 수 있도록 옵션이 있습니다.

지금은 기억이 가물한데 ^^;

하여간 찾아서 그 컴파일 옵션을 알려드리겠습니다.

그러면 65G도 제어가 되실것 입니다.

그럼^^;

체스맨의 이미지

open64, lseek64, stat64 등과 같은 시스템 콜이 있습니다.

Orion Project : http://orionids.org

leilei의 이미지

헤더를 보시면 "64"가 붙는 평션들을 찾으실 수 있습니다.

예를 들어 stdio.h를 보시면 fopen64.. 등등을 볼 수 있네요.. :)
open64는 fcntl.h에...

urmajest의 이미지

답변해주신 분들 정말 감사드립니다.

사실 제 질문의 요지는 C가 아닌 C++에서 가능한 방법이었습니다.

fstream을 이용한다던지 말이죠.

C++ 을 이용해서 할 수 있는 방법은 없는건가요?

우선 fopen64, fgetpos64, fsetpos64를 이용해서 코딩을 했는데,

"C++"만을 이용한 코딩을 하고 싶었거든요 -_-

에구..안되는건가요? -_-

Prentice의 이미지

약간 거리가 있는 얘기지만 혹시나 싶어서 적어봅니다.

GCC 3.4에서 바뀐 점 중에 libstdc++에서 큰 파일(32bit CPU의 경우 2GB 이상 파일)도 다룰 수 있다는 점이 있습니다.

그렇다면 GCC 3.4 보다 오래된 libstdc++에서는 32bit CPU를 쓰는 이상 2GB가 넘는 파일을 다룰 수 없었다는 얘기인 것인가요?

wongi의 이미지

g++ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g3 -o tstlargefile_cc tstlargefile_cc.cc

http://gcc.gnu.org/ml/gcc-bugs/2003-03/msg00532.html

Quote:
[root@galaxy sandbox]# g++ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g3 -o tstlargefile_cc tstlargefile_cc.cc
[root@galaxy sandbox]# ./tstlargefile_cc lf_cc.out
..................................................[root@galaxy sandbox]# ls -lh
total 4.9G
-rw-r--r-- 1 root root 4.9G Apr 23 11:32 lf_cc.out
-rwxr-xr-x 1 root root 28k Apr 23 11:23 tstlargefile_cc
-rw-r--r-- 1 root root 530 Apr 23 11:23 tstlargefile_cc.cc

돌아가는구만요... :)

KISS...
Keep It Small and Simple

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.