Don't ask to ask, just ask | |
PerlMonks |
Re: can't manage to use BerkeleyDB::Envby flexvault (Monsignor) |
on Aug 23, 2012 at 14:24 UTC ( [id://989322]=note: print w/replies, xml ) | Need Help?? |
This is a code snippet from a working program, to show you how to use the 'BerkeleyDB::Env'. Think of the environment as a holding directory, where related databases are stored, and the related BerkeleyDB internal files and cache are stored. I wouldn't use '/tmp' since it's world readable, but that's your call. I pulled a lot of unrelated testing out, so it may not compile, but you'll be in the ballpark. This shows with the default cache size, but I usually 16MB in production. One important thing, I left the 'Fcntl' in to help you think about the potential for race conditions. I use an extra file to lock the BerkeleyDB environment before using the BerkeleyDB calls. Without it, you are suspect to many race conditions. If you are going to run in single user mode, you don't need it. But for multi-user or multi-tasking you'll save yourself a lot of headaches. BerkeleyDB is very fast and you don't notice any overhead with the extra flocks.
If you super search on BerkeleyDB, you'll find some examples of subroutines that show the external locking and some timing information. Good Luck! "Well done is better than well said." - Benjamin Franklin
In Section
Seekers of Perl Wisdom
|
|