c++ - Can't read file larger than 2GB in Ubuntu 64 bit OS -


solved @nsilent22, suggestion. change made in seekg() function parameter.

nd_file.seekg( (long)(block_number)*disk_block_size ); nd_file.read((char*)(&count), sizeof(int)); 

original post

i know similar questions have been asked , answered earlier. still need existing program.

hardware spec : ubuntu 14.04, 64 bit, ext4 file system

i have old program creating disk based index. when index file reaches 2.1gb, following read() function inputs wrong value , program aborts.

nd_file.seekg(block_number*disk_block_size); nd_file.read((char*)(&count), sizeof(int)); 

based on similar posts, have put #define _file_offset_bits 64 @ beginning of each file.

following make file:

gcc=g++ -d_file_offset_bits=64 ndt: main.o utility.o logclass.o      g++ -g -o ndtree main.o utility.o logclass.o      rm *.o main.o: main.cpp config.h box_queries.h meta_entry.h meta_node.h dir_entry.h dir_node.h leaf_entry.h leaf_node.h logclass.h nd_tree.h node.h utility.h      g++ -g -c main.cpp utility.o: utility.cpp utility.h      g++ -g -c utility.cpp logclass.o: logclass.cpp logclass.h      g++ -g -c logclass.cpp clean:     rm -f *.o 

@updated

portion of output log : here block-174 called twice. in first case, read function input disk data correctly. however, in last line, #entries 0 not right. , happens when block::524288 assigned. therefore, guess read() , seekg() don't work properly.

id       newblockid   parentblockid  #entriesinblock  index #maxentries    554192   524280       463255         149              61    255        554193   524281       463255         149              75    255 554194   524282       497389         131              80    255 **554195     524283       174            250              26    255** 554196   524284       125426         142              77    255 554197   524285       223509         130             118    255 554198   524286       262212         136              72    255 554199   524287       224407         142             121    255 terminate called after throwing instance of 'std::out_of_range'   what():  vector::_m_range_check **554200     524288       174              0             227    255** aborted (core dumped) 

should need use different functions reading file contents? suggestions appreciated.

well answer simple. basing on comment:

const int disk_block_size; unsigned int block_number;

both variables of type int (one unsigned), computed value is... int. , size of int on 64-bit ubuntu system is... 32 bits. on 64-bit system compile simple code:

#include <stdio.h>  int main(void) {     int x = 2000000000;     int y = 4;     printf("x = %d\n", x);     printf("y = %d\n", y);     printf("x * y = %d\n", x * y);     printf("x * y = %ld\n", (long)(x * y));     printf("x * y = %ld\n", (long)(x) * y);     return 0; } 

and you'll see ought do.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -