summaryrefslogtreecommitdiff
path: root/docs/tutorials/021/combine.shar
blob: 1df4875c662dda0d475de0cdb1e393fb9bbf2daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-09-21 22:49 EDT by <jcej@chiroptera.tragus.org>.
# Source directory was `/home/jcej/projects/ACE_wrappers/docs/tutorials/021'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#    409 -rw-rw-r-- hdr
#     47 -rw-rw-r-- bodies
#   2302 -rw-rw-r-- page01.pre
#    282 -rw-rw-r-- page02.pre
#    202 -rw-rw-r-- page03.pre
#    288 -rw-rw-r-- page04.pre
#     61 -rw-rw-r-- page05.pre
#    604 -rw-rw-r-- page06.pre
#    786 -rw-rw-r-- page04.pst
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
if mkdir _sh05289; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= hdr ==============
if test -f 'hdr' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'hdr' '(file already exists)'
else
  $echo 'x -' extracting 'hdr' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hdr' &&
<HTML>
<HEAD>
X   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
X   <META NAME="Author" CONTENT="James CE Johnson">
X   <TITLE>ACE Tutorial 021</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">
X
<CENTER><B><FONT SIZE=+2>ACE Tutorial 021</FONT></B></CENTER>
X
<CENTER><B><FONT SIZE=+2>Pooling your memories</FONT></B></CENTER>
X
<P>
<HR WIDTH="100%">
SHAR_EOF
  $shar_touch -am 0103180599 'hdr' &&
  chmod 0664 'hdr' ||
  $echo 'restore of' 'hdr' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'hdr:' 'MD5 check failed'
9ffa6eb1308f4872f390b30f74a6de3b  hdr
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'hdr'`"
    test 409 -eq "$shar_count" ||
    $echo 'hdr:' 'original size' '409,' 'current size' "$shar_count!"
  fi
fi
# ============= bodies ==============
if test -f 'bodies' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'bodies' '(file already exists)'
else
  $echo 'x -' extracting 'bodies' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'bodies' &&
PAGE=2
server.cpp
client.cpp
mpool.h
mpool.cpp
SHAR_EOF
  $shar_touch -am 0106135399 'bodies' &&
  chmod 0664 'bodies' ||
  $echo 'restore of' 'bodies' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'bodies:' 'MD5 check failed'
470abefc6e5e401ad9ffdfa76e3ca143  bodies
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bodies'`"
    test 47 -eq "$shar_count" ||
    $echo 'bodies:' 'original size' '47,' 'current size' "$shar_count!"
  fi
fi
# ============= page01.pre ==============
if test -f 'page01.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page01.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page01.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page01.pre' &&
X      The previous two tutorials were very primitive & basic.  They
X      showed very simple uses of shared memory and memory mapped
X      files.
X    <p>
X      If we move the level of abstraction up just a bit, the next
X      thing we encounter is memory pools.  ACE_Malloc&lt;&gt; provides 
X      this to us.
X    <p>
X      In this tutorial, we'll use ACE_Malloc&lt;&gt; to create a
X      memory pool that is sharable between a client and server.  We'll 
X      use a memory mapped file to provide the physical storage but
X      shared memory works just as well.
<P>
Kirthika's abstract:
<UL>
The ACE_Malloc class is templatised by the type of memory pool
and the lock for it. The name of the memory pool provided can be used 
in the "bind" call made by the server. This helps the other party
wanting to access it do so by a "find" call. The ACE_Malloc will
allocate
memory and on a "malloc" will return memory chunks from its reserve.
When the memory chunk is freed by the user, it will be appended to the
free list maintained by the class. Unless a "remove" is done explicitly,
the memory wont be returned to the OS. Various memory pool types can be
used,
X ACE_MMap_Memory_Pool,ACE_Sbrk_Memory_Pool to name a few. 
For further details: <A HREF="../../ace/Memory_Pool.h">ace/Memory_Pool.h</A>.
<P>
In this tutorial, a ACE_Malloc class with ACE_MMAP_MEMORY_POOL
and a semophore for syncronisation has been used. This is locked by
the server initially and released after it writes into it so that
the client waiting for it can go ahead and do its job. There is yet
another semaphore used by the server to exit only after the client
has finished its task, which is locked by the client at the start
and released when its done.  
<P>
Some more information regarding memory management:
ACE also provides the ACE_Allocator class which uses
dynamic binding and is flexible, though at a cost of using 
virtual pointer tables. Also, there is an ACE_Allocator_Adapter class
which has an ACE_Allocator interface but ACE_Malloc functionality.  
<P>
Bottomline: Memory can be managed either using the ACE_Allocator
set of classes which uses polymorphism and is thus flexible but not as
efficient as the templatised version which is the ACE_Malloc set of
classes which are more efficient but not as felxible.
X
</UL>
SHAR_EOF
  $shar_touch -am 0403170799 'page01.pre' &&
  chmod 0664 'page01.pre' ||
  $echo 'restore of' 'page01.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page01.pre:' 'MD5 check failed'
45c14d3a6d1c0cf26b68e83f6878a854  page01.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page01.pre'`"
    test 2302 -eq "$shar_count" ||
    $echo 'page01.pre:' 'original size' '2302,' 'current size' "$shar_count!"
  fi
fi
# ============= page02.pre ==============
if test -f 'page02.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page02.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page02.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page02.pre' &&
X      The key components for creating the memory pool are:
X    <ul>
X      <li>Create and name the pool
X      <li>Allocate a chunk (region) of memory from the pool
X      <li>Name the allocated region
X    </ul>
X    The rest of it is just critical sections and data manipulation.
<hr>
SHAR_EOF
  $shar_touch -am 0103180899 'page02.pre' &&
  chmod 0664 'page02.pre' ||
  $echo 'restore of' 'page02.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page02.pre:' 'MD5 check failed'
6742359e1f990299bdab5992d0629d96  page02.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page02.pre'`"
    test 282 -eq "$shar_count" ||
    $echo 'page02.pre:' 'original size' '282,' 'current size' "$shar_count!"
  fi
fi
# ============= page03.pre ==============
if test -f 'page03.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page03.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page03.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page03.pre' &&
X	  The client side is a little simpler than the server.  Mainly 
X	  because we don't try to delete the pool:
X	<ul>
X	  <li>Create an Allocator to access the pool
X	  <li>Find the named region
X	</ul>
<hr>
SHAR_EOF
  $shar_touch -am 0106135499 'page03.pre' &&
  chmod 0664 'page03.pre' ||
  $echo 'restore of' 'page03.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page03.pre:' 'MD5 check failed'
e47af5a3f933ac9eafbb4aae007aa0e6  page03.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page03.pre'`"
    test 202 -eq "$shar_count" ||
    $echo 'page03.pre:' 'original size' '202,' 'current size' "$shar_count!"
  fi
fi
# ============= page04.pre ==============
if test -f 'page04.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page04.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page04.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page04.pre' &&
X	  Everything common the server & client is kept here.  In
X	  particular, the Constants class where we keep the names &
X	  semaphore keys.
X	<p>
X	  The Allocator class is just a thin wrapper around
X	  ACE_Malloc&lt;&gt; that moves some of the details out of the
X	  application logic.
<hr>
SHAR_EOF
  $shar_touch -am 0106135699 'page04.pre' &&
  chmod 0664 'page04.pre' ||
  $echo 'restore of' 'page04.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page04.pre:' 'MD5 check failed'
2366f1603bd1e71955eb8ee3429ca402  page04.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pre'`"
    test 288 -eq "$shar_count" ||
    $echo 'page04.pre:' 'original size' '288,' 'current size' "$shar_count!"
  fi
fi
# ============= page05.pre ==============
if test -f 'page05.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page05.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page05.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page05.pre' &&
And here we have the implementation of the Allocator...
<hr>
SHAR_EOF
  $shar_touch -am 0403171399 'page05.pre' &&
  chmod 0664 'page05.pre' ||
  $echo 'restore of' 'page05.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page05.pre:' 'MD5 check failed'
eef6d56514a448ce6cd962b7d34dd50f  page05.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page05.pre'`"
    test 61 -eq "$shar_count" ||
    $echo 'page05.pre:' 'original size' '61,' 'current size' "$shar_count!"
  fi
fi
# ============= page06.pre ==============
if test -f 'page06.pre' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page06.pre' '(file already exists)'
else
  $echo 'x -' extracting 'page06.pre' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page06.pre' &&
X	  As you can see, using a memory pool is really rather easy.  The
X	  most difficult part, as always, is with the synch mechanisms.
X	<P>
X	  The other nice thing about ACE_Malloc&lt;> is that you can swap
X	  between System V shared memory and memory mapped files just by
X	  changing the template parameters.  The truly adventurous will
X	  likely find a runtime way of doing this.
X	<p>
X	  
X	<ul>
X	  <li><A HREF="Makefile">Makefile</A>
X	  <li><A HREF="server.cpp">server.cpp</A>
X	  <li><A HREF="client.cpp">client.cpp</A>
X	  <li><A HREF="mpool.h">mpool.h</A>
X	  <li><A HREF="mpool.cpp">mpool.cpp</A>
X	</ul>
SHAR_EOF
  $shar_touch -am 0106142499 'page06.pre' &&
  chmod 0664 'page06.pre' ||
  $echo 'restore of' 'page06.pre' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page06.pre:' 'MD5 check failed'
68fa5365d4add68561720a1f24bb980f  page06.pre
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page06.pre'`"
    test 604 -eq "$shar_count" ||
    $echo 'page06.pre:' 'original size' '604,' 'current size' "$shar_count!"
  fi
fi
# ============= page04.pst ==============
if test -f 'page04.pst' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'page04.pst' '(file already exists)'
else
  $echo 'x -' extracting 'page04.pst' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'page04.pst' &&
<HR>
X    The really hard stuff is done by the ACE_Malloc<> template.  This
X      template takes two parameters.<sup>*</sup>  The first is a
X      memory pool class to use.  ACE has several, I've choosen one
X      that uses a memory-mapped file.  The second parameter is a lock
X      class of some sort.  This is needed so that the ACE_Malloc<> can 
X        protect its internal data.  Note that you still have to
X        provide your own mutex around the data you put into the
X        malloc'd area.
X
<P>
X          * Actually, some implementations may require a different
X          number of parameters.
X        That's why ACE uses those funky macros.  ACE_MMAP_MEMORY_POOL
X        for instance turns into ACE_MMAP_Memory_Pool on Linux but may
X        do other things on your platform.
SHAR_EOF
  $shar_touch -am 0313161099 'page04.pst' &&
  chmod 0664 'page04.pst' ||
  $echo 'restore of' 'page04.pst' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'page04.pst:' 'MD5 check failed'
9e40019f1599341ac0dac0f3eee47341  page04.pst
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'page04.pst'`"
    test 786 -eq "$shar_count" ||
    $echo 'page04.pst:' 'original size' '786,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh05289
exit 0