 |
|
| Computers Forum Index » Computer - Databases - Berkeley » Heap problem in window when using DB_DBT_APPMALLOC... |
|
Page 1 of 1 |
|
| Author |
Message |
| Kevin iu... |
Posted: Sat Sep 19, 2009 3:07 am |
|
|
|
Guest
|
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);
} |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Sat Dec 05, 2009 12:01 am
|
|