The typical procedure for using dbstl is:

    1. Optionally create and open your own Berkeley DB environment and database handles using the DB C++ API. If you perform these opens using the C++ API, make sure to perform necessary environment and database configurations at that time.

    2. At this time, you can also use dbstl calls that are specific to Berkeley DB. For example, you can use Berkeley DB specific calls that manage transaction begin/commit/abort, handle registration, and so forth. While these calls are part of dbstl, they have no equivalence in the C++ STL APIs.

    The following program listing provides two code fragments. You can find more example code in the and dbstl/test directories.

    The first snippet initializes a db_vector container of 100 elements, with an in-memory anonymous database internally created by dbstl. The only difference between this and C++ STL is dbstl requires one more type parameter: ElementHolder<int>. The ElementHolder class template should be used for every type of dbstl container that will store C++ primitive data types, such as , float, char *, wchar_t *, and so forth. But these class templates should not be used for class types for reasons that we explain in the following chapters.

    In the second code snippet, the assignment:

    1. strmap[str] = str2;

    The rest of the code used in these snippets is identical to the code you would use for C++ STL containers. However, by using dbstl, you are storing data into a Berkeley DB database. If you create your own database with backing files on disk, your data or objects can persist and be restored when the program runs again.