NavigationBanners
Active forum topicsRecent blog postsUser loginWho's new
Who's onlineThere are currently 1 user and 969 guests online.
Online users:
|
Add new commentLive Compression of a GDBM DatabaseSubmitted by Bill St. Clair on Sun, 2008-02-03 21:02.
A GDBM database file is an easy way to persistently store key/value pairs. Loom uses one for its backing store. One problem with these databases is that they become fragmented over time, with lots of unfilled empty space: holes. They need to be periodically compressed. Patrick Chkeroff and I came up with a neat mechanism to do live compression. He has seen the Loom database file get 20 times bigger than it needed to be. He plans to integrate something similar to this mechanism into the Loom code. The basic idea mirrors Lisp two-space incremental garbage collectors, but is a little simpler. Call the original GDBM database the "old" database. We're going to open a second database, called the "new" database. And change the database access code so that it will over time copy the old database to the new one, leaving the new one with a compressed version of the data in the old one, plus any changes the user code has made during the copy operation. There's a working example in GDBM.php, in my Loom folder. You can copy and paste from that page or download it and my other Loom related code from billstclair.com/loom. The idea is simple. There are three operations on a database, read, write, and delete (implemented in the code by get() and put() functions, where put() of a blank value means delete). read($key):
write($key, $value):
delete($key)
To each of the operations, I also add a call to the copysome() function, which copies some values from the old database to the new one. After all values have been copied, we close both databases, delete the old one, which is now empty, rename new to old, and reopen the new old database. When the user requests another copy, we open another new database and start again. copysome:
At no time is it necessary to close the database for off-line compression. All you need is enough disk space to store two copies of the data, and a slight slow-down in access speed during the copy. ( categories: Loom )
Reply |
BlogrollLewRockwell.comQuotesEvery man, woman, and responsible child has an unalienable individual, civil, Constitutional, and human right to obtain, own, and carry, openly or concealed, any weapon -- rifle, shotgun, handgun, machinegun, anything -- any time, any place, without asking anyone's permission. -- L. Neil Smith Reread that pesky first clause of the Second Amendment. It doesn't say what any of us thought it said. What it says is that infringing the right of the people to keep and bear arms is treason. What else do you call an act that endangers "the security of a free state"? And if it's treason, then it's punishable by death. I suggest due process, speedy trials, and public hangings. -- L. Neil Smith Based on 253 journal articles, 99 books, 43 government publications, and some of its own empirical work, the panel couldn't identify a single gun control regulation that reduced violent crime, suicide or accidents. -- John Lott, commenting on the National Academy of Sciences report (PDF) on gun control laws Zero Aggression Principle ("Zap") "A libertarian is a person who believes that no one has the right, under any circumstances, to initiate force against another human being, or to advocate or delegate its initiation. Those who act consistently with this principle are libertarians, whether they realize it or not. Those who fail to act consistently with it are not libertarians, regardless of what they may claim." -- L. Neil Smith Formerly called the "Non-Aggression Principle", or "NAP" Why Did It Have to be... Guns? Make no mistake: all politicians -- even those ostensibly on the side of guns and gun ownership -- hate the issue and anyone, like me, who insists on bringing it up. They hate it because it's an X-ray machine. It's a Vulcan mind-meld. It's the ultimate test to which any politician -- or political philosophy -- can be put. If a politician isn't perfectly comfortable with the idea of his average constituent, any man, woman, or responsible child, walking into a hardware store and paying cash -- for any rifle, shotgun, handgun, machinegun, anything -- without producing ID or signing one scrap of paper, he isn't your friend no matter what he tells you. If he isn't genuinely enthusiastic about his average constituent stuffing that weapon into a purse or pocket or tucking it under a coat and walking home without asking anybody's permission, he's a four-flusher, no matter what he claims. What his attitude -- toward your ownership and use of weapons -- conveys is his real attitude about you. And if he doesn't trust you, then why in the name of John Moses Browning should you trust him? -- L. Neil Smith "Tell me," I was once asked, "What do you think about gun control? Give me the short answer." To which I replied, "If you try to take our firearms we will kill you." -- Mike Vanderboegh The state can only survive as long as a majority is programmed to believe that theft isn't wrong if it's called taxation or asset forfeiture or eminent domain, that assault and kidnapping isn't wrong if it's called arrest, that mass murder isn't wrong if it's called war. -- Bill St. Clair Monthly ArchivesTTLB |
Recent comments
23 hours 20 min ago
1 day 12 hours ago
1 day 19 hours ago
4 days 12 hours ago
5 days 7 hours ago
5 days 22 hours ago
5 days 22 hours ago
1 week 2 days ago
1 week 3 days ago
1 week 4 days ago