Etaki
Etaki

Reputation: 1

C++ jsoncpp: Segfault while reading json file in a loop

Json file:

[
    {"A":"sample1","B":"sample2","C":"sample3,"D":"sample4"},       
    {"A":"sample5","B":"sample6","C":"sample7,"D":"sample8"}, 
    {"A":"samplea","B":"sampleb","C":"sampleb,"D":"sampleb"},
    .
    .
    .
    }
]

I have 2075980 such entries in my input file

struct entry_t 
{
    U64 param;
}
entry_t entry; 
Json::Value root;
Json::Reader reader;
ifstream test("json_file", ifstream::binary);    
if(!reader.parse(test, root, false))
{
    cout << reader.getFormattedErrorMessages() << endl;}
else
{ 
    for(unsigned int i = 0; i < root.size(); i++)
    {  
        entry.param   = root[i].get("A", "null").asInt();
    }
}

above code works fine until 472783th loop. in the following loop, getting a seg fault while trying to access "entry.param"

I am new to C++ and jsoncpp and not able to figure out the cause of the seg fault.

Upvotes: 0

Views: 400

Answers (1)

Sga
Sga

Reputation: 3658

Tested in a Windows OS, JsonCPP allocates 2.5 GB to store your file in memory...

You must switch to 64bit or use another native lib with a smaller memory footprint (see here)

memory usage

Upvotes: 0

Related Questions