dbTalk Databases Forums  

Heap problem in window when using DB_DBT_APPMALLOC

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Heap problem in window when using DB_DBT_APPMALLOC in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Kevin iu
 
Posts: n/a

Default Heap problem in window when using DB_DBT_APPMALLOC - 09-18-2009 , 10:07 PM






I am new to the berkeley DB. When working on the secondary database
with multiple keys in the window (XP) with VS2008, an execption is
throw when the bekeley db release the memory. Any idea?


int callbackIndexByPoolTypes( Db *sdbp, // secondary db
handle
const Dbt *pkey, // primary db record's key
const Dbt *pdata, // primary db record's data
Dbt *skey) // secondary db record's key
{
Dbt *tmpdbt;
char* tmpdata1 = (char*)malloc(3);
char* tmpdata2 = (char*)malloc(3);
strcpy(tmpdata1, "12");
strcpy(tmpdata2, "34");



tmpdbt = (Dbt*)malloc(sizeof(Dbt) * 2);
memset(tmpdbt, 0, sizeof(Dbt) * 2);

// Now assign secondary keys to each element of the array.
tmpdbt[0].set_data(tmpdata1);
tmpdbt[0].set_size(3);
tmpdbt[0].set_flags(DB_DBT_APPMALLOC);
tmpdbt[1].set_data(tmpdata2);
tmpdbt[1].set_size(3);
tmpdbt[0].set_flags(DB_DBT_APPMALLOC);

// Now we set flags for the returned Dbt. DB_DBT_MULTIPLE is
// required in order for DB to know that the Dbt references an
// array. In addition, we set DB_DBT_APPMALLOC because we
// dynamically allocated memory for the Dbt's data field.
// DB_DBT_APPMALLOC causes DB to release that memory once it
// is done with the returned Dbt.
skey->set_flags(DB_DBT_MULTIPLE | DB_DBT_APPMALLOC);

// Point the results data field to the arrays of Dbts
skey->set_data(tmpdbt);


// Indicate the returned array is of size 2
skey->set_size(2);




return (0);
}

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.