summaryrefslogtreecommitdiff
path: root/docs/tutorials/021/page01.html
blob: 93d2d2ad4076c5b30e5e0ab559a4bd82b7dc45a6 (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
<!-- $Id$ -->
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="James CE Johnson">
   <TITLE>ACE Tutorial 021</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

<CENTER><B><FONT SIZE=+2>ACE Tutorial 021</FONT></B></CENTER>

<CENTER><B><FONT SIZE=+2>Pooling your memories</FONT></B></CENTER>

<P>
<HR WIDTH="100%">
      The previous two tutorials were very primitive & basic.  They
      showed very simple uses of shared memory and memory mapped
      files.
    <p>
      If we move the level of abstraction up just a bit, the next
      thing we encounter is memory pools.  ACE_Malloc&lt;&gt; provides
      this to us.
    <p>
      In this tutorial, we'll use ACE_Malloc&lt;&gt; to create a
      memory pool that is sharable between a client and server.  We'll
      use a memory mapped file to provide the physical storage but
      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,
 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.

</UL>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page02.html">Continue This Tutorial</A>]</CENTER>