Search code examples
cbufferberkeley-db

How to limit Berkeley DB's buffer?


I need to limit the maximum size of Berkeley's buffer. I've tried using the code below, but the buffer keeps growing.

DB_ENV *db_env; 
u_int32_t env_flags;
char *DBNOMENV = "";
db_env_create(&db_env, 0);
db_env->set_cache_max(db_env, 0.1, 0);
env_flags = DB_CREATE | DB_INIT_MPOOL;
db_env->open(db_env, DBNOMENV, env_flags, 0);
DB *BDB_database;
db_create(&BDB_database, db_env, 0);

Solution

  • You want DB_ENV->set_cachesize: set_cachesize, from the Oracle docs.

    What's the purpose of set_cache_max, when all it appears to do is limit the number you can specify with some other function call? You got me. There's probably some nuance here, but in practice, set_cache_max is only there to to add to the confusion.

    Note that both of these functions only accept integer arguments for the sizing. You'll need set_cachesize(db_env, 0, 100*1024*1024, 1); to do what you were trying to do with that 0.1.

    "Number of caches" should be 1.