[fpc-pascal]Databases and FPC
PBrooks at mhg.co.za
Mon May 5 13:36:03 CEST 2003
Use a KSAM/ISAM [Keyed/Indexed Sequential Access Method] file. They are much
faster than databases, particularly relational ones and very easy to code
All you need to do is make the size of the file around 40% bigger than you
expect it ever to be (and if it gets up to 50% then rebuild an re-populate
it) then produce a hash number from the names and write to that address. You
have to have a good hash algorithm (tons about) and a policy for migrating
secondaries but it is all fairly straightforward. If your records are large
you might have two files, one for the keys and one for the data, then you
don't even need a hash key, you just insert the names in batches (say each
evening or every hour if it is really busy) where you re-sort the whole key
file and add the items in alphabetical order, a quick sort [maybe literally
if you like it] will yield the name and you simply add the records to the
end of the other file.
Another method sometimes used is to create an alphabetic directory
hierarchy. Top level directories a,b,c...z and so on so that I would get the
directory /p/e/t/e/r/ /b/r/o/o/k/s/ then you just put the records into files
in the bottom directory - if there are duplicates then either ask a question
to disambiguate them or require somebody to select another name. It is quite
quick but relies on your having a disc volume that, on an unix system, has
plenty of inodes and a small blocking factor - otherwise this is rather a
wasteful option. It is dead simple to code though. The nice thing about this
is that, if you have a half decent file system, you can allow arbitrary
lengths of name and take case into account. Just remember that human beings
are pretty bad at being able to type in even their own name twice without
making a mistake. You can do some quite clever offering of alternatives with
this system - if one letter is wrong there may only be a few directories
that could fit, so, by doing a bit of tree walking you can offer a list of a
few names that cope with simple spelling errors and transpositions.
From: fpc-pascal-admin at lists.freepascal.org
[mailto:fpc-pascal-admin at lists.freepascal.org] On Behalf Of James Mills
Sent: 05 May 2003 12:59
To: fpc-pascal at lists.freepascal.org
Subject: [fpc-pascal]Databases and FPC
I dunno if any of you have ever written an entire IRC Services in FPC
before, but for the past few months I've been porting my 5 year old
windows (delphi) version to linux.
I'm wondering about databases however... The old windows version used to
use a flat-file database to store nickname and channel registrations,
the port I'm writing also uses the same thing. However this obviously
will be slow if say an IRC network has 10,000 nicks/channels etc...
Is there anything anyone would suggest I do ? I have only a couple of
ideas, perhaps you might have a few more than I...
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal