    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Letters to the Editor</title>
        <link>https://members.accu.org/index.php/articles/373</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Letters to the Editor + Overload Journal #52 - Dec 2002</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c186/">LettersEditor</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c191/">52</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c186-191/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c186+191/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Letters to the Editor</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 02 December 2002 21:57:50 +00:00 or Mon, 02 December 2002 21:57:50 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e11" id="d0e11"></a>Comments on
&quot;Applied Reading - Taming Shared Memory&quot; by Josh Walker in Overload
51.</h2>
</div>
<p>I really enjoyed to see an article about shared memory in
Overload 51. For one, it (re-)promoted a solution for a frequent
problem (managing common access to shared objects) that is
generally much more appropriate than the usual solution
&quot;multi-threading&quot;. The overwhelming number of publications (books
and articles) about multi-threading had the effect that most
developers think that multithreading is the proper solution to the
sharing problem (and even for problems that share virtually no
resources). Therefore, it is really good to see an article about a
long-known solution that is in my opinion nearly always more
appropriate.</p>
<p>Then, I enjoyed the article because I'm now working for quite a
while on a library to make the use of shared memory easier.
Unfortunately, it turned out that using standard containers or
strings inside of shared memory is virtually impossible. Not that
there is a fundamental problem with containers in shared memory.
Though it is not completely easy, it is possible to provide
<tt class="literal">shm_ptr</tt> as a full blown pointer type
(including pointer arithmetics). And providing a wrapper around
<tt class="literal">shm_allocator</tt> that implements the STL
allocator requirements is pretty easy. But unfortunately, the C++
standard gives library implementors the leeway to ignore the type
<tt class="literal">Allocator::pointer</tt> and instead just assume
that it is a raw pointer. And though the standard explicitely
encourages library implementors not to use this leeway, I didn't
yet come across an implementation that actually worked when
<tt class="literal">Allocator::pointer</tt> was not a raw pointer.
(Probably I just looked in the wrong places.)</p>
<p>What is really sad is that when I looked at the implementation,
it seemed that there is no real reason for that, but just a general
sloppiness by using &quot;<tt class="literal">T*</tt>&quot; instead of
&quot;<tt class="literal">Allocator::pointer</tt>&quot;. (The main reason for
this is probably historical as well as an unwillingness to really
think about the requirements of &quot;<tt class=
"literal">Allocator::pointer</tt>&quot; and document them as an
implementation defined enhancement.) So, to make shared memory
really comfortable, you need to provide your own replacements for
the standard containers and string. Or you ensure that the shared
memory segment is mapped to the same address in all processes, but
this is an option that is rarely available.</p>
<p>Some final notes: Whether shared memory is actually the proper
solution for the problem at hand I'm not so sure. If only, because
it's pretty hard to implement a clean and safe message queue. But
then, if a different solution would have been chosen, we wouldn't
have got this excellent article. And a minor issue with the
presented code: Why is the size parameter of the <tt class=
"literal">shm_segment</tt> constructor of type &quot;<tt class=
"literal"><tt class="literal">int</tt></tt>&quot;, while the return of
<tt class="literal"><tt class="literal">get_size()</tt></tt> and
the internal <tt class="literal">size_</tt> member are of type
&quot;<tt class="literal">unsigned int</tt>&quot;. The proper type would
probably be &quot;<tt class="literal">size_t</tt>&quot;.</p>
<p>Detlef Vollmann &lt;dv@vollman.ch&gt;</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e65" id="d0e65"></a>Response to
Detlef Vollmann's comments</h2>
</div>
<p>I found Detlef's comments on using standard containers in shared
memory very interesting. It is unfortunate that current
implementations fail to support this natural and useful extension.
I hope this will change as libraries and compilers mature.</p>
<p>As I mentioned in the article, the choice of shared memory was
influenced by my own skill set. It has so far proved an adequate
solution, though I agree that it may not be the ideal one. Of
course, it was also a useful topic for exposition.</p>
<p>As Detlef keenly points out, the <tt class=
"literal">shm_segment</tt> members and methods concerned with size
should use <tt class="literal">size_t</tt>. The use of <tt class=
"literal">signed int</tt> is just sloppiness on my part. Finally,
let me thank Detlef for his comments. I hope more readers will send
their feedback on Overload articles.</p>
<p>Josh Walker joshwalker1@earthlink.net</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
