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>DbEnv::set_shm_key()</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++ API Reference" /> 10 <link rel="up" href="env.html" title="Chapter 5. The DbEnv Handle" /> 11 <link rel="prev" href="envset_msgfile.html" title="DbEnv::set_msgfile()" /> 12 <link rel="next" href="envset_thread_count.html" title="DbEnv::set_thread_count()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DbEnv::set_shm_key()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="envset_msgfile.html">Prev</a> </td> 22 <th width="60%" align="center">Chapter 5. 23 The DbEnv Handle 24 </th> 25 <td width="20%" align="right"> <a accesskey="n" href="envset_thread_count.html">Next</a></td> 26 </tr> 27 </table> 28 <hr /> 29 </div> 30 <div class="sect1" lang="en" xml:lang="en"> 31 <div class="titlepage"> 32 <div> 33 <div> 34 <h2 class="title" style="clear: both"><a id="envset_shm_key"></a>DbEnv::set_shm_key()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db_cxx.h> 39 40int 41DbEnv::set_shm_key(long shm_key); </pre> 42 <p> 43 Specify a base segment ID for Berkeley DB environment shared memory 44 regions created in system memory on VxWorks or systems supporting 45 X/Open-style shared memory interfaces; for example, UNIX systems 46 supporting <span class="bold"><strong>shmget</strong></span>(2) and related 47 System V IPC interfaces. 48 </p> 49 <p> 50 This base segment ID will be used when Berkeley DB shared memory 51 regions are first created. It will be incremented a small integer 52 value each time a new shared memory region is created; that is, if the 53 base ID is 35, the first shared memory region created will have a 54 segment ID of 35, and the next one will have a segment ID between 36 55 and 40 or so. A Berkeley DB environment always creates a master 56 shared memory region; an additional shared memory region for each of 57 the subsystems supported by the environment (Locking, Logging, Memory 58 Pool and Transaction); plus an additional shared memory region for 59 each additional memory pool cache that is supported. Already existing 60 regions with the same segment IDs will be removed. See <a href="../../programmer_reference/env_region.html" class="olink">Shared Memory Regions</a> for more 61 information. 62 </p> 63 <p> 64 The intent behind this method is two-fold: without it, applications 65 have no way to ensure that two Berkeley DB applications don't attempt 66 to use the same segment IDs when creating different Berkeley DB 67 environments. In addition, by using the same segment IDs each time 68 the environment is created, previously created segments will be 69 removed, and the set of segments on the system will not grow without 70 bound. 71 </p> 72 <p> 73 The database environment's base segment ID may also be configured 74 using the environment's <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> file. The 75 syntax of the entry in that file is a single line with the string 76 "set_shm_key", one or more whitespace characters, and the ID. Because 77 the <a href="../../programmer_reference/env_db_config.html#env_db_config.DB_CONFIG" class="olink">DB_CONFIG</a> 78 file is read when the database environment is opened, it will silently 79 overrule configuration done before that time. 80 </p> 81 <p> 82 The <code class="methodname">DbEnv::set_shm_key()</code> method configures operations performed 83 using the specified <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> handle, not all 84 operations performed on the underlying database environment. 85 </p> 86 <p> 87 The <code class="methodname">DbEnv::set_shm_key()</code> method may not be called after the 88 <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> method is called. 89 If the database environment already exists when 90 <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> is called, the 91 information specified to <code class="methodname">DbEnv::set_shm_key()</code> must be consistent 92 with the existing environment or corruption can occur. 93 </p> 94 <p> 95 The <code class="methodname">DbEnv::set_shm_key()</code> <span> 96 97 <span> 98 method either returns a non-zero error value or throws an 99 exception that encapsulates a non-zero error value on 100 failure, and returns 0 on success. 101 </span> 102 </span> 103 </p> 104 <div class="sect2" lang="en" xml:lang="en"> 105 <div class="titlepage"> 106 <div> 107 <div> 108 <h3 class="title"><a id="id1674312"></a>Parameters</h3> 109 </div> 110 </div> 111 </div> 112 <div class="sect3" lang="en" xml:lang="en"> 113 <div class="titlepage"> 114 <div> 115 <div> 116 <h4 class="title"><a id="id1674540"></a>shm_key</h4> 117 </div> 118 </div> 119 </div> 120 <p> 121 The <span class="bold"><strong>shm_key</strong></span> parameter is the base 122 segment ID for the database environment. 123 </p> 124 </div> 125 </div> 126 <div class="sect2" lang="en" xml:lang="en"> 127 <div class="titlepage"> 128 <div> 129 <div> 130 <h3 class="title"><a id="id1674689"></a>Errors</h3> 131 </div> 132 </div> 133 </div> 134 <p> 135 The <code class="methodname">DbEnv::set_shm_key()</code> <span> 136 137 <span> 138 method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> 139 exception, encapsulating one of the following non-zero errors, or return one 140 of the following non-zero errors: 141 </span> 142 </span> 143 </p> 144 <div class="sect3" lang="en" xml:lang="en"> 145 <div class="titlepage"> 146 <div> 147 <div> 148 <h4 class="title"><a id="id1674524"></a>EINVAL</h4> 149 </div> 150 </div> 151 </div> 152 <p> 153 If the method was called after <a class="xref" href="envopen.html" title="DbEnv::open()">DbEnv::open()</a> 154 was called; or if an invalid flag value or parameter was specified. 155 </p> 156 </div> 157 </div> 158 <div class="sect2" lang="en" xml:lang="en"> 159 <div class="titlepage"> 160 <div> 161 <div> 162 <h3 class="title"><a id="id1674719"></a>Class</h3> 163 </div> 164 </div> 165 </div> 166 <p> 167 <a class="link" href="env.html" title="Chapter 5. The DbEnv Handle">DbEnv</a> 168 </p> 169 </div> 170 <div class="sect2" lang="en" xml:lang="en"> 171 <div class="titlepage"> 172 <div> 173 <div> 174 <h3 class="title"><a id="id1674724"></a>See Also</h3> 175 </div> 176 </div> 177 </div> 178 <p> 179 <a class="xref" href="env.html#envlist" title="Database Environments and Related Methods">Database Environments and Related Methods</a> 180 </p> 181 </div> 182 </div> 183 <div class="navfooter"> 184 <hr /> 185 <table width="100%" summary="Navigation footer"> 186 <tr> 187 <td width="40%" align="left"><a accesskey="p" href="envset_msgfile.html">Prev</a> </td> 188 <td width="20%" align="center"> 189 <a accesskey="u" href="env.html">Up</a> 190 </td> 191 <td width="40%" align="right"> <a accesskey="n" href="envset_thread_count.html">Next</a></td> 192 </tr> 193 <tr> 194 <td width="40%" align="left" valign="top">DbEnv::set_msgfile() </td> 195 <td width="20%" align="center"> 196 <a accesskey="h" href="index.html">Home</a> 197 </td> 198 <td width="40%" align="right" valign="top"> DbEnv::set_thread_count()</td> 199 </tr> 200 </table> 201 </div> 202 </body> 203</html> 204