A friend showed me this example of a command line phone contact list using a plaintext file as database.
File format:
Code: Select all
name: street address: city, state zip: extra fields...
One used your favorite editor to create the file. use the script or alias named 'phone' SEARCHTERM can be content of any field:
Code: Select all
grep SEARCHTERM plaintextfilename | tr : \n
The output, for example 'phone name', gives
Code: Select all
name
street address
city, state zip
extra fields
Simple, elegant. I used that script for years on many a unix system. An appropriate filebased db, imho.
A thousand variables really isn't that much memory. Unless your 'constants' are larger than 1k a piece (that's a lot of text or a gigantic number) you'll use less than 1 megabyte of memory. You want speed, this is the way. I'd definitely code a simple hash or array from constants in a header file as a first try.
Second thing to consider is: Are these really constants, or do you want to change them, however rarely? If this data changes slowly and never changes format a file is what I would suggest.
If this database is in anyway a moving target which changes at moderate to fast rates you need a db product which has already done the heavy lifting when it comes to sessions and transactions and indexes and such. The leanest and simplest I've used is sqlite. There is no server to set up. The database resides in a single file and your application talks to it using a library linked to your app. It uses a subset of SQL, the lingua franca of relational databases and the basic stuff of creating and checking entries is fairly simple.
Db servers like MySQL, Postgresql and the rest are heavy duty workhorses. Don't go there unless you need to or just want to learn. It is my opinion that they would be overkill for your stated requirements.
Any conversation about a sufficiently complex subject is indistinguishable from babble.