Forum Stats

  • 3,839,871 Users
  • 2,262,546 Discussions
  • 7,901,088 Comments

Discussions

secondary index key generation function, documentation error?

526209
526209 Member Posts: 2
edited Aug 2, 2006 11:38AM in Berkeley DB
Hi all,

I've been looking at documentation on secondary indexes here:

http://www.sleepycat.com/docs/ref/am/second.html

I noticed in the example code a reference to Dbt flag "DB_DBT_APPMALLOC", but it seems as though this flag does not exist. Looking at the Dbt reference page here:

http://www.sleepycat.com/docs/api_cxx/dbt_class.html

the valid Dbt flags are: DB_DBT_MALLOC, DB_DBT_REALLOC, DB_DBT_USERMEM, DB_DBT_PARTIAL. So does this "DB_DBT_APPMALLOC" refer to DB_DBT_USERMEM?

In any case, the problem I'm working through is this; I have a secondary key which must be extracted from Dbt * pdata and stored in user allocated memory. Unfortunately, the documented example doesn't go over this explicitly and I'm a bit new to BDB, so I'm hesitant..

When allocating memory for use by the Dbt secondary key, how long does this memory have to be valid for the secondary index to do its thing? When is it safe to free this? I'm guessing it's intimately tied to the lifetime of the primary key/data Dbt pair, but it isn't very clear from docs.

Thanks for any help!

Comments

  • 526209
    526209 Member Posts: 2
    Ok, so I've poked around a bit more and have found more info on DB_DBT_APPMALLOC:

    http://www.sleepycat.com/docs/api_cxx/db_associate.html

    """
    If the callback function needs to allocate memory for the data field rather than simply pointing into the primary key or datum, the flags field of the returned Dbt should be set to DB_DBT_APPMALLOC, which indicates that Berkeley DB should free the memory when it is done with it.
    """

    This seems to answer my earlier questions. Thanks for your patience :)
This discussion has been closed.