diff options
Diffstat (limited to 'docs/tutorials/021/page05.html')
-rw-r--r-- | docs/tutorials/021/page05.html | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/docs/tutorials/021/page05.html b/docs/tutorials/021/page05.html deleted file mode 100644 index c72b87ac570..00000000000 --- a/docs/tutorials/021/page05.html +++ /dev/null @@ -1,88 +0,0 @@ -<!-- $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%"> -And here we have the implementation of the Allocator... -<hr> -<PRE> - -<font color=red>// $Id$</font> - -<font color=blue>#include</font> "<font color=green>mpool.h</font>" - -<font color=blue>#if !defined</font> (<font color=purple>ACE_LACKS_SYSV_SHMEM</font>) - -<font color=red>/* - Set the values of all of the constants. This guarantees that client - and server don't get confused. - */</font> -const int <font color=#008888>Constants::SEM_KEY_1</font> = ACE_DEFAULT_SEM_KEY + 1; -const int <font color=#008888>Constants::SEM_KEY_2</font> = ACE_DEFAULT_SEM_KEY + 2; - -const int <font color=#008888>Constants::SHMSZ</font> = 27; -const char * <font color=#008888>Constants::SHMDATA</font> = "<font color=green>abcdefghijklmnopqrstuvwxyz</font>"; - -const char * <font color=#008888>Constants::PoolName</font> = "<font color=green>SharedMemoryPool</font>"; -const char * <font color=#008888>Constants::RegionName</font> = "<font color=green>Alphabet</font>"; - -<font color=red>/* - We have to create a copy of the _name parameter in case the caller - has dynamically allocated it. The pool_ is set to NULL & will be - allocated by the accessor. - */</font> -<font color=#008888>Allocator::Allocator</font> (const char *_name) - : name_ (<font color=#008888>ACE_OS::strdup</font> (_name)), - pool_ (0) -{ - if (name_ == 0) - ACE_ERROR ((LM_ERROR, "<font color=green>(%P) %p</font>", - "<font color=green><font color=#008888>Allocator::Allocator</font> cannot strdup pool name</font>")); -} - -<font color=#008888>Allocator::~Allocator</font> (void) -{ - <font color=red>/* - strdup() uses malloc(), so we must use free() to clean up. - */</font> - if (name_) - <font color=#008888>ACE_OS::free</font> (name_); - - <font color=red>// delete doesn't really care if you give it a NULL pointer.</font> - delete pool_; -} - -<font color=red>/* - Allocate the pool. Since we return a reference, we'll be in really - bad shape if the new fails. This is a great place to throw an - exception! - The other concern is thread safety. If two threads call here at - about the same time, we may create the pool twice. We can't use a - Singleton because we want to have multiple Allocator instances. The - Singleton techniques can be used though. - */</font> - -<font color=#008888>Allocator::pool_t</font> & -<font color=#008888>Allocator::pool</font> (void) -{ - if (pool_ == 0) - pool_ = new pool_t (name_); - - return *pool_; -} - -<font color=blue>#endif</font> <font color=red>/* ACE_LACKS_SYSV_SHMEM */</font> -</PRE> -<P><HR WIDTH="100%"> -<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page06.html">Continue This Tutorial</A>]</CENTER> - |