|
From: Steve W. <sw...@wc...> - 2000-07-16 04:09:04
|
I have been working on the refactoring of the DBM support, and came back
to the problem of the memory leak. I wrote a test script and did some
experimenting, and here's what I found:
When you insert a key/value into a DBM and that pair already exists:
if the value is less than or equal to the existing value, the
space is reused,
else new space is allocated and the old space is not reclaimed.
The dbmdelete() function does not help at all. If you loop over a DBM and
delete all key/values, and then replace them with the same pairs, there is
no change in the file size.
However if you delete all pairs, close the DBM and reopen it and reinsert
all key/value pairs, the DBM file size doubles.
If you delete all pairs and insert new ones with slightly larger value
sizes you more than double the file size.
This would suggest (if I feel ambitious) that for a DBM implementation all
pages should be padded out to a certain size, say 500 bytes, and when they
are fetched the padding is stripped. This probably wouldn't be too hard
with the perl regexp package and spaces or $FieldSeparator.
test script below,
sw
<?
$page = implode("", file("pgsrc/AddingPages"));
$h = dbmopen("/tmp/AAA", "c");
$time = time();
for ($x = 0; $x < 500; $x++) {
if (dbmexists($h, "$x")) {
$page = dbmfetch($h, "$x");
$page .= "$x$time";
}
dbmdelete($h, "$x");
dbmreplace($h, "$x", $page);
}
echo system("ls -l /tmp/AAA");
dbmclose($h);
?>
...............................ooo0000ooo.................................
Hear FM quality freeform radio through the Internet: http://wcsb.org/
home page: www.wcsb.org/~swain
|