Copyright (C) 2000-2012 |
Whole document tree
Closing a databaseThe only other operation that we need for our simple example is closing the database, and cleaning up the DB handle. It is necessary that the database be closed. The most important reason for this is that Berkeley DB runs on top of an underlying buffer cache. If the modified database pages are never explicitly flushed to disk and the database is never closed, changes made to the database may never make it out to disk, because they are held in the Berkeley DB cache. As the default behavior of the close function is to flush the Berkeley DB cache, closing the database will update the on-disk information. The DB->close interface takes two arguments:
Here's what the code to call DB->close looks like: #include <sys/types.h> #include <stdio.h> #include <db.h> Note that we do not necessarily overwrite the ret variable, as it may contain error return information from a previous Berkeley DB call. |