I'm planning on writing a program in C++ that will go through a database of numbers and do assorted statistical analysys on them. What I need to know is, what form of data storage should I use? I could go XML, but wouldn't that be overkill for a database of 1000 or more sets of 6 values per set? And CSV/TSV text files just seem too simple. These values will probably end up in an array during processing, so what would be the most efficient method for storing the database?
Number Database in C++
If the database really does not scale and remains small enough to reside completely in memory, I'd go for binary files with a fixed record length:
typedef struct tagMyRecord
{
int Index;
char someFixedInfo[256];
BOOL SomeBool;
//.... other fields
}MyRecord;
HANDLE hFile = ::CreateFile(...);
DWORD numRecords = ::FileSize(hFile, NULL) / sizeof(MyRecord);
MyRecord *ptr = new MyRecord[numRecords];
DWORD dwRead = 0;
if( ::ReadFile(hFile, (void*)ptr, sizeof(MyRecord) * numRecords, &dwRead, NULL) )
{
//...
}
This is the most native and fastest way to go; no parsing of delimiters and suchlike.
If you want to sort and search them, I'd recommend using std::vector instead of new[] and defining your own operator(<) for the struct.
hth,
herd
PS: This is even simpler than CSV - it always pays to keep it simple.
Wow. Um, okay, guess it's time to get out the ol' C++ book. Thanks! I'll take this into account ![]()
Aqua-Soft Forums