Fixed Length Flat File Table Algorithms in c++

574 views Asked by At

I am doing simple project for table processing using flat files in c++. I have two type of files to access the table data. 1) Index File. ( employee.idx ) 2) Table File. ( employee.tbl )

In index file, I have table details in the format of tab delimited . i.e., Column-name Column-Type Column-Offset Column-Size

for example, employee.idx

ename string 0 10
eage number 10 2
ecity string 12 10

In Table file, I have the data in the format of Fixed Length. for example, employee.tbl

first     25Address0001
second    31Address0002

Here I will explain my algorithm what I did in my program.

1) First I have loaded index file data in 2D vector String ( Index Vector ) using fstream.

2) This is my code to load Table File Data into 2D

while (fsMain)
{

    if (!getline( fsMain, s )) break;

    string s_str;

    for(size_t i=0;i<idxTable.size();i++)

    {
        int fieldSize=stoi(idxTable[i].at(3));

        string data (s,stoi(idxTable[i].at(2)),fieldSize);

        string tmp=trim_right_inplace(data);

        recordVec.push_back( tmp );

    }

    mainTable.push_back(record);


    recordVec.clear();  

    s="";
}

Ok. Now my question is , " Is there any other better way to load the Fixed length data to memory ? ". I checked this process for 60 tables with 200 Records. It takes nearly 20 Seconds. But I want to load 100 tables with 200 records within one Second. But It takes more time. How can I improve efficiency for this task ?

0

There are 0 answers