Bug in API docs? -
08-03-2006
, 11:51 AM
Hi,
While testing out the memory pool API I encountered a bug in the
documentation for DbMpoolFile::get
(http://www.sleepycat.com/docs/api_cxx/memp_fget.html). In big bold
letters it explains that
"Page numbers begin at 0; that is, the first page in the file is page
number 0, not page number 1."
The C API says the same thing. However, the test program below seems to
argue otherwise. The first page written is 1, and trying to read page 0
fails. I'm running BDB v 4.4.20, x86, Linux.
Did I miss something?
Ryan
#include "db_cxx.h"
#include <cstdio>
static const size_t PAGE_SIZE = 512;
int main() {
DbEnv env(0);
// use a small number of pages
env.set_cachesize(0, PAGE_SIZE*4, 0);
env.set_tmp_dir("tmp");
env.set_msgfile(stdout);
env.open(NULL, DB_CREATE | DB_PRIVATE | DB_THREAD | DB_INIT_MPOOL,
0);
// open a file in the pool, set to delete on finish
DbMpoolFile* pool;
env.memp_fcreate(&pool, 0);
pool->set_flags(DB_MPOOL_UNLINK, true);
pool->open(NULL, DB_CREATE, 0644, PAGE_SIZE);
printf("<<<< Starting stats:\n");
env.memp_stat_print(DB_STAT_ALL);
const char* actions = "wwwwRwRwRRRR";
bool done = false;
db_pgno_t rpn=0, wpn;
void* p;
while(!done) {
switch(*(actions++)) {
case 'r':
case 'R':
pool->get(&rpn, 0, &p);
printf("\n\n<<<< Read page %d:\n", rpn);
// if(p)
pool->put(p, DB_MPOOL_CLEAN | DB_MPOOL_DISCARD);
rpn++;
break;
case 'w':
case 'W':
pool->get(&wpn, DB_MPOOL_NEW, &p);
printf("\n\n<<<< Wrote page %d:\n", wpn);
memset(p, 0, PAGE_SIZE);
memcpy(p, &wpn, sizeof(wpn));
pool->put(p, DB_MPOOL_DIRTY);
break;
default:
done = true;
}
env.memp_stat_print(0);
}
pool->close(0);
env.close(0);
return 0;
} |