<p>You can persist all bytes in a chunk of contiguous memory by constructing an <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
object A(use malloc to allocate the required number of bytes for A.data and copy the bytes to be stored into A.data, set other fields as necessary) and store A into a container, e.g. </p>
<p>db_vector<DbstlDbt>, this stores the bytes rather than the object A into the underlying database. The <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
class can help you avoid memory leaks, so it is strongly recommended that you use <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
derives from Dbt class, and it does an deep copy on copy construction and assignment --by calling malloc to allocate its own memory and then copying the bytes to it; Conversely the destructor will free the memory on destruction if the data pointer is non-NULL. The destructor assumes the memory is allocated via malloc, hence why you are required to call malloc to allocate memory in order to use <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
simply inherits all methods from Dbt with no extra new methods except the constructors/destructor and assignment operator, so it is easy to use.</p>
<p>In practice you rarely need to use <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
or Dbt because dbstl enables you to store any complex objects or primitive data. Only when you need to store raw bytes, e.g. a bitmap, do you need to use <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
is the right class to use to store any object into Berkeley DB via dbstl without memory leaks.</p>
<p>Don't free the memory referenced by <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
objects, it will be freed when the <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
object is destructed.</p>
<p>Please refer to the two examples using <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
in TestAssoc::test_arbitrary_object_storage and TestAssoc::test_char_star_string_storage member functions, which illustrate how to correctly use <aclass="link"href="DbstlDbt.html"title="Chapter25. DbstlDbt">DbstlDbt</a>
in order to store raw bytes.</p>
<p>This class handles the task of allocating and de-allocating memory internally. Although it can be used to store data which cannot be handled by the <aclass="link"href="DbstlElemTraits.html"title="Chapter26. DbstlElemTraits">DbstlElemTraits</a>
class, in practice, it is usually more convenient to register callbacks in the <aclass="link"href="DbstlElemTraits.html"title="Chapter26. DbstlElemTraits">DbstlElemTraits</a>
class for the type you are storing/retrieving using dbstl. </p>