Debian Codegraph @

docs/api_reference/STL/DbstlDbt.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <title>Chapter 25.  DbstlDbt</title>
7 <link rel="stylesheet" href="apiReference.css" type="text/css" />
8 <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9 <link rel="start" href="index.html" title="Berkeley DB C++ Standard Template Library API Reference" />
10 <link rel="up" href="index.html" title="Berkeley DB C++ Standard Template Library API Reference" />
11 <link rel="prev" href="stlElementRef_DB_STL_value.html" title="_DB_STL_value" />
12 <link rel="next" href="stlDbstlDbtdstr_DbstlDbt.html" title="~DbstlDbt" />
13 </head>
14 <body>
15 <div xmlns="" class="navheader">
16 <div class="libver">
17 <p>Library Version 11.2.5.3</p>
18 </div>
19 <table width="100%" summary="Navigation header">
20 <tr>
21 <th colspan="3" align="center">Chapter 25. 
22 DbstlDbt </th>
23 </tr>
24 <tr>
25 <td width="20%" align="left"><a accesskey="p" href="stlElementRef_DB_STL_value.html">Prev</a> </td>
26 <th width="60%" align="center"> </th>
27 <td width="20%" align="right"> <a accesskey="n" href="stlDbstlDbtdstr_DbstlDbt.html">Next</a></td>
28 </tr>
29 </table>
30 <hr />
31 </div>
32 <div class="chapter" lang="en" xml:lang="en">
33 <div class="titlepage">
34 <div>
35 <div>
36 <h2 class="title"><a id="DbstlDbt"></a>Chapter 25. 
37 DbstlDbt </h2>
38 </div>
39 </div>
40 </div>
41 <p>You can persist all bytes in a chunk of contiguous memory by constructing an <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
42 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>
43 <p>db_vector&lt;DbstlDbt&gt;, this stores the bytes rather than the object A into the underlying database. The <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
44 class can help you avoid memory leaks, so it is strongly recommended that you use <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
45 rather than Dbt class.</p>
46 <p><a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
47 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 <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
48 .</p>
49 <p><a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
50 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>
51 <p>In practice you rarely need to use <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
52 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 <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
53 .</p>
54 <p>Hence, <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
55 is the right class to use to store any object into Berkeley DB via dbstl without memory leaks.</p>
56 <p>Don't free the memory referenced by <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
57 objects, it will be freed when the <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
58 object is destructed.</p>
59 <p>Please refer to the two examples using <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
60 in TestAssoc::test_arbitrary_object_storage and TestAssoc::test_char_star_string_storage member functions, which illustrate how to correctly use <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
61 in order to store raw bytes.</p>
62 <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 <a class="link" href="DbstlElemTraits.html" title="Chapter 26.  DbstlElemTraits">DbstlElemTraits</a>
63 class, in practice, it is usually more convenient to register callbacks in the <a class="link" href="DbstlElemTraits.html" title="Chapter 26.  DbstlElemTraits">DbstlElemTraits</a>
64 class for the type you are storing/retrieving using dbstl. </p>
65 <h4><a id="idp51587824"></a> Public Members </h4>
66 <div class="informaltable">
67 <table border="1" width="80%">
68 <colgroup>
69 <col />
70 <col />
71 </colgroup>
72 <thead>
73 <tr>
74 <th>Member</th>
75 <th>Description</th>
76 </tr>
77 </thead>
78 <tbody>
79 <tr>
80 <td>
81 <a class="xref" href="DbstlDbt.html#stlDbstlDbtDbstlDbt" title="DbstlDbt">DbstlDbt</a>
82 </td>
83 <td>
84 <p>Construct an object with an existing chunk of memory of size1 bytes, refered by data1,. </p> </td>
85 </tr>
86 <tr>
87 <td>
88 <a class="xref" href="stlDbstlDbtdstr_DbstlDbt.html" title="~DbstlDbt">~DbstlDbt</a>
89 </td>
90 <td>
91 <p>The memory will be free'ed by the destructor. </p> </td>
92 </tr>
93 <tr>
94 <td>
95 <a class="xref" href="stlDbstlDbtoperator_assign.html" title="operator=">operator=</a>
96 </td>
97 <td>
98 <p>The memory will be reallocated if neccessary. </p> </td>
99 </tr>
100 </tbody>
101 </table>
102 </div>
103 <h4><a id="idp51593232"></a>
104 Group</h4>
105 <p>
106 <a class="xref" href="dbstl_helper_classes.html" title="Chapter 21.  Dbstl Helper Classes">
107 Dbstl Helper Classes </a>
108 </p>
109 <p>
110 </p>
111 <div class="sect1" lang="en" xml:lang="en">
112 <div class="titlepage">
113 <div>
114 <div>
115 <h2 class="title" style="clear: both"><a id="stlDbstlDbtDbstlDbt"></a>DbstlDbt</h2>
116 </div>
117 </div>
118 </div>
119 <div class="sect2" lang="en" xml:lang="en">
120 <div class="titlepage">
121 <div>
122 <div>
123 <h3 class="title"><a id="stlDbstlDbtDbstlDbt_details"></a>Function Details</h3>
124 </div>
125 </div>
126 </div>
127 <pre class="programlisting">
128 DbstlDbt(void *data1,
129 u_int32_t size1)
130 </pre>
131 <p>Construct an object with an existing chunk of memory of size1 bytes, refered by data1,. </p>
132 <pre class="programlisting">
133 DbstlDbt()
134 </pre>
135 <pre class="programlisting">
136 DbstlDbt(const DbstlDbt &amp;d)
137 </pre>
138 <p>This copy constructor does a deep copy. </p>
139 </div>
140 <div class="sect2" lang="en" xml:lang="en">
141 <div class="titlepage">
142 <div>
143 <div>
144 <h3 class="title"><a id="idp51589656"></a>Class</h3>
145 </div>
146 </div>
147 </div>
148 <p>
149 <a class="link" href="DbstlDbt.html" title="Chapter 25.  DbstlDbt">DbstlDbt</a>
150 </p>
151 </div>
152 </div>
153 </div>
154 <div class="navfooter">
155 <hr />
156 <table width="100%" summary="Navigation footer">
157 <tr>
158 <td width="40%" align="left"><a accesskey="p" href="stlElementRef_DB_STL_value.html">Prev</a> </td>
159 <td width="20%" align="center"> </td>
160 <td width="40%" align="right"> <a accesskey="n" href="stlDbstlDbtdstr_DbstlDbt.html">Next</a></td>
161 </tr>
162 <tr>
163 <td width="40%" align="left" valign="top">_DB_STL_value </td>
164 <td width="20%" align="center">
165 <a accesskey="h" href="index.html">Home</a>
166 </td>
167 <td width="40%" align="right" valign="top"> ~DbstlDbt</td>
168 </tr>
169 </table>
170 </div>
171 </body>
172 </html>