dbTalk Databases Forums  

DBT - DB_DBT_MALLOC/DB_DBT_REALLOC

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


Discuss DBT - DB_DBT_MALLOC/DB_DBT_REALLOC in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Derick Smith
 
Posts: n/a

Default DBT - DB_DBT_MALLOC/DB_DBT_REALLOC - 09-30-2003 , 04:48 PM






Hi!
I was able to get my previous email to work (I could not reply to it
directly using google.) by using DB_DBT_MALLOC/DB_DBT_REALLOC.

I have more questions:

Are we required to free a DBT if we use DB_DBT_MALLOC/DB_DBT_REALLOC?
or will BerkeleyDB do this for us?

If I memset a DBT to 0, when I previously set the flag to
DB_DBT_MALLOC and populated the DBT with a DB->get, will BerkeleyDB
free that memory?

If I use DB_DBT_REALLOC, do I initially have to use DB_DBT_MALLOC,
then after I have populated the DBT, set the DBT flag to
DB_DBT_REALLOC?

Thanks for any responses.
Eric

Previous posting:
Newsgroups: comp.databases.berkeley-db
Subject: DBT question - BerkeleyDB - www.sleepycat.com
NNTP-Posting-Host: 142.206.2.12
Message-ID: <99805581.0309300618.549f9c1b (AT) posting (DOT) google.com>

Hi!

I don't know if anyone can respond to this:

Is is possible to put the DBT in a struct, then declare an array of
DBTs? This array will be declared dynamically.

I want to call DBcursor->c_get and DB->get multiple times and store
the result(s) in this structure. Then close the cursors.

I know berkeley manages the memory and what the DBT points to, but how
long will these DBT references last? Will berkeley handle all the
memory/disk manangement? Will this work successfully? I am going to be
testing this, but if it will not work it would be nice to know now.
Will this work if the DB->set_cachesize is small?

Thanks in advance to anyone who responds.

typedef struct {
DBT key;
DBT data;
} GCT_MITEM;

GCT_MITEM mydbts[100];



From Berkeley help file:
When returning a key/data item to the application, Berkeley DB will
store into the data structure element a pointer to a byte string of
size bytes, and the memory to which the pointer refers will be
allocated and managed by Berkeley DB.

Reply With Quote
  #2  
Old   
Keith Bostic
 
Posts: n/a

Default Re: DBT - DB_DBT_MALLOC/DB_DBT_REALLOC - 10-01-2003 , 03:24 PM






niagara_man (AT) hotmail (DOT) com (Derick Smith) wrote in message news:<99805581.0309301348.327a7567 (AT) posting (DOT) google.com>...
Quote:
I was able to get my previous email to work (I could not reply to it
directly using google.) by using DB_DBT_MALLOC/DB_DBT_REALLOC.

I have more questions:

Are we required to free a DBT if we use DB_DBT_MALLOC/DB_DBT_REALLOC?
or will BerkeleyDB do this for us?
The application must free the memory referenced by the key or
data pointers when these flags are used. The memory allocated
when these flags are used is the responsibility of the application.

Quote:
If I memset a DBT to 0, when I previously set the flag to
DB_DBT_MALLOC and populated the DBT with a DB->get, will BerkeleyDB
free that memory?
No. Any pointer allocated based on the DB_DBT_MALLOC flag
will never be freed by Berkeley DB.

Quote:
If I use DB_DBT_REALLOC, do I initially have to use DB_DBT_MALLOC,
then after I have populated the DBT, set the DBT flag to
DB_DBT_REALLOC?
You can use DB_DBT_REALLOC initially, without first using
DB_DBT_MALLOC.

Regards,
--keith

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Keith Bostic bostic (AT) sleepycat (DOT) com
Sleepycat Software Inc. keithbosticim (ymsgid)
118 Tower Rd. +1-781-259-3139
Lincoln, MA 01773 http://www.sleepycat.com


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.