Forum Stats

  • 3,840,116 Users
  • 2,262,569 Discussions
  • 7,901,154 Comments

Discussions

is it a bug ?

529558
529558 Member Posts: 8
edited Aug 23, 2006 7:35AM in Berkeley DB
I found a weird phenomenon.

---------------------code 1-------------------------
Dbt dbKey((void*) lpKey ,dwKeyLen);
Dbt dbData;
int nRes;
//dbData.set_flags (DB_DBT_MALLOC);

int nRes=m_pDb->get (NULL,&dbKey,&dbData,0);
// Db::get() will cause error without the line dbData.set_flags (DB_DBT_MALLOC);


-----------------------code 2----------------------------------------
Dbt dbKey,dbData;
int nRes;
nRes=m_pCursor->get (&dbKey,&dbData,DB_FIRST);
// Dbc::get() run normally without any initialization for dbKey and dbData.

why does Db::get() function need the initialization to dbData and Dbc::get() has no such need ?
is it a bug of BerkeleyDb () ? thanks.

Comments

  • 524300
    524300 Member Posts: 340
    Hi,

    The issue is that when the DB_THREAD flag is set on a database handle, the handle cannot maintain memory for Dbts between calls (because there may be concurrent calls from multiple threads), so one of the DBT allocation flags are required.

    That doesn't apply to cursors, which are only accessed from a single thread.

    Regards,
    Michael.
This discussion has been closed.