diff options
Diffstat (limited to 'docs/tutorials/Chap_3')
-rw-r--r-- | docs/tutorials/Chap_3/Chap_3.zip | bin | 3004 -> 0 bytes | |||
-rw-r--r-- | docs/tutorials/Chap_3/ex01.html | 107 | ||||
-rw-r--r-- | docs/tutorials/Chap_3/ex02.html | 135 |
3 files changed, 0 insertions, 242 deletions
diff --git a/docs/tutorials/Chap_3/Chap_3.zip b/docs/tutorials/Chap_3/Chap_3.zip Binary files differdeleted file mode 100644 index c99463d18d9..00000000000 --- a/docs/tutorials/Chap_3/Chap_3.zip +++ /dev/null diff --git a/docs/tutorials/Chap_3/ex01.html b/docs/tutorials/Chap_3/ex01.html deleted file mode 100644 index a722e9a9b6d..00000000000 --- a/docs/tutorials/Chap_3/ex01.html +++ /dev/null @@ -1,107 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="Ambreen Ilyas"> - <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> - <TITLE>Example 1</TITLE> -</HEAD> -<BODY> -<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> -<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers -Guide.</FONT> -<BR><FONT COLOR="#CC0000">//// Chapter: "Memory Management"</FONT> -<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> -<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> -<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> -<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> -<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> - -<P><FONT COLOR="#CC0000">//Example 1 </FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Malloc.h"</FONT> -<BR><FONT COLOR="#FF0000">//A chunk of size 1K is created</FONT> -<BR><FONT COLOR="#000099">typedef</FONT> <FONT COLOR="#993300">char</FONT><FONT COLOR="#666600"> -MEMORY_BLOCK[1024];</FONT> -<BR> -<BR> - -<P><FONT COLOR="#FF0000">//Create an ACE_Cached_Allocator which is passed -in the type of the</FONT> -<BR><FONT COLOR="#FF0000">//chunk that it must pre-allocate and assign -on the free</FONT> -<BR><FONT COLOR="#FF0000">//list</FONT> -<BR><FONT COLOR="#000000">typedef ACE_Cached_Allocator<MEMORY_BLOCK,ACE_SYNCH_MUTEX> -Allocator;</FONT> -<BR> -<BR>class MessageManager{ -<BR>public: -<BR><FONT COLOR="#FF0000">//The constructor is passed the number of chunks -that the allocator should pre-allocate //and maintain on its free list.</FONT> -<BR>MessageManager(int n_blocks): -<BR> allocator_(n_blocks),message_count_(0){} - -<P><FONT COLOR="#FF0000">//Allocate memory for a message using the Allocator</FONT> -<BR>void allocate_msg(const char *msg){ -<BR> mesg_array_[message_count_]= -<BR> (char*)allocator_.malloc(ACE_OS::strlen(msg)); -<BR> ACE_OS::strcpy(mesg_array_[message_count_],msg); -<BR> message_count_++; -<BR> } - -<P><FONT COLOR="#FF0000">//Free all memory allocated. This will cause the -chunks to be returned</FONT> -<BR><FONT COLOR="#FF0000">//to the allocators internal free list and NOT -to the OS.</FONT> -<BR>void free_all_msg(){ -<BR> for(int i=0;i<message_count_;i++) -<BR> allocator_.free(mesg_array_[i]); -<BR> message_count_=0; -<BR> } -<BR>void display_all_msg(){ -<BR> for(int i=0;i<message_count_;i++) -<BR> ACE_OS::printf("%s\n",mesg_array_[i]); -<BR> } -<BR> -<BR>private: -<BR> char *mesg_array_[20]; -<BR> Allocator allocator_; -<BR> int message_count_; -<BR>}; -<BR> - -<P>int main(int argc, char* argv[]){ - -<P>if(argc<2){ -<BR> ACE_OS::printf("Usage: egXX <Number of blocks>\n"); -<BR> exit(1); -<BR> } -<BR> -<BR><FONT COLOR="#FF0000">//Instatiate the Memory Manager class</FONT> -<BR>int n_blocks=ACE_OS::atoi(argv[1]); -<BR>MessageManager mm(n_blocks); -<BR> - -<P><FONT COLOR="#FF0000">//Use the Memory Manager class to assign messages -and free them.</FONT> <FONT COLOR="#FF0000">Run this in your</FONT> -<BR><FONT COLOR="#FF0000">//debug environment and you will notice that -//the</FONT> <FONT COLOR="#FF0000">amount of memory your program uses</FONT> -<BR><FONT COLOR="#FF0000">//after Memory Manager has been</FONT> <FONT COLOR="#FF0000">instantiated -remains the same. That means the</FONT> -<BR><FONT COLOR="#FF0000">//Cached Allocator</FONT> <FONT COLOR="#FF0000">controls -or manages all the memory for the application.</FONT> - -<P><FONT COLOR="#FF0000">//Do forever.</FONT> -<BR>while(1){ -<BR> <FONT COLOR="#FF0000">//allocate the messages somewhere</FONT> -<BR> for(int i=0; i<n_blocks;i++) -<BR> mm.allocate_msg("Hi there"); -<BR> <FONT COLOR="#FF0000">//show the messages</FONT> -<BR> mm.display_all_msg(); -<BR> -<BR> for( i=0;i<n_blocks;i++) -<BR> mm.free_all_msg(); -<BR> } -<BR>} - -<P> <A HREF="ex02.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_3/ex02.html b/docs/tutorials/Chap_3/ex02.html deleted file mode 100644 index b425bfb9565..00000000000 --- a/docs/tutorials/Chap_3/ex02.html +++ /dev/null @@ -1,135 +0,0 @@ -<HTML> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="Ambreen Ilyas"> - <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> - <TITLE>Example 2</TITLE> -</HEAD> -<BODY> -<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> -<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers -Guide.</FONT> -<BR><FONT COLOR="#CC0000">//// Chapter: "Memory Management"</FONT> -<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> -<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> -<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> -<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> -<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> - -<P><FONT COLOR="#CC0000">//Example 2</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Shared_Memory_MM.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Malloc.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Malloc_T.h"</FONT> -<BR><FONT COLOR="#000099">#define </FONT><FONT COLOR="#663366">DATA_SIZE -100</FONT> -<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> MESSAGE1 -"Hiya over there client process"</FONT> -<BR><FONT COLOR="#000099">#define </FONT><FONT COLOR="#663366">MESSAGE2 -"Did you hear me the first time?"</FONT> -<BR>LPCTSTR poolname="My_Pool"; - -<P><FONT COLOR="#000000">typedef ACE_Malloc<ACE_SHARED_MEMORY_POOL,ACE_Null_Mutex> -Malloc_Allocator;</FONT> - -<P>static void -<BR>server (void){ -<BR> <FONT COLOR="#FF0000">//Create the memory allocator passing it -the shared memory</FONT> -<BR> <FONT COLOR="#FF0000">//pool that you want to use</FONT> -<BR> Malloc_Allocator shm_allocator(poolname); - -<P> <FONT COLOR="#FF0000">//Create a message, allocate memory for -it and bind it with</FONT> -<BR><FONT COLOR="#FF0000"> //a name so that the client can the find -it in the memory</FONT> -<BR><FONT COLOR="#FF0000"> //pool</FONT> -<BR> char* Message1=(char*)shm_allocator.malloc(strlen(MESSAGE1)); -<BR> ACE_OS::strcpy(Message1,MESSAGE1); -<BR> shm_allocator.bind("FirstMessage",Message1); -<BR> ACE_DEBUG((LM_DEBUG,"<<%s\n",Message1)); -<BR> -<BR><FONT COLOR="#FF0000"> //How about a second message</FONT> -<BR> char* Message2=(char*)shm_allocator.malloc(strlen(MESSAGE2)); -<BR> ACE_OS::strcpy(Message2,MESSAGE2); -<BR> shm_allocator.bind("SecondMessage",Message2); -<BR> ACE_DEBUG((LM_DEBUG,"<<%s\n",Message2)); -<BR> -<BR> <FONT COLOR="#FF0000">//Set the Server to go to sleep for a while -so that the client has</FONT> -<BR><FONT COLOR="#FF0000"> //a chance to do its stuff</FONT> -<BR> ACE_DEBUG((LM_DEBUG, -<BR> "Server done writing.. going to sleep zzz..\n\n\n")); -<BR> ACE_OS::sleep(2); -<BR> -<BR><FONT COLOR="#FF0000"> //Get rid of all resources allocated by -the server. In other</FONT> -<BR><FONT COLOR="#FF0000"> //words get rid of the shared memory pool -that had been</FONT> -<BR><FONT COLOR="#FF0000"> //previously allocated</FONT> -<BR> shm_allocator.remove(); -<BR> -<BR>} -<BR> - -<P>static void -<BR>client(void){ -<BR> <FONT COLOR="#FF0000">//Create a memory allocator. Be sure that -the client passes</FONT> -<BR><FONT COLOR="#FF0000"> // in the "right" name here so that both -the client and the</FONT> -<BR><FONT COLOR="#FF0000"> //server use the same memory pool. We wouldnt -want them to</FONT> -<BR><FONT COLOR="#FF0000"> // BOTH create different underlying pools.</FONT> -<BR> Malloc_Allocator shm_allocator(poolname); - -<P><FONT COLOR="#FF0000"> //Lets get that first message. Notice that -the find is looking up the</FONT> -<BR><FONT COLOR="#FF0000"> //memory based on the "name" that was bound -to it by the server.</FONT> -<BR> void *Message1; -<BR> if(shm_allocator.find("FirstMessage",Message1)==-1){ -<BR> ACE_ERROR((LM_ERROR, -<BR> "Client: Problem cant find data that server has -sent\n")); -<BR> ACE_OS::exit(1); -<BR> } -<BR> ACE_OS::printf(">>%s\n",(char*) Message1); -<BR> ACE_OS::fflush(stdout); - -<P> <FONT COLOR="#FF0000">//Lets get that second message now.</FONT> -<BR> void *Message2; -<BR> if(shm_allocator.find("SecondMessage",Message2)==-1){ -<BR> ACE_ERROR((LM_ERROR,"Client: Problem cant find data that server -has sent\n")); -<BR> ACE_OS::exit(1); -<BR> } -<BR> ACE_OS::printf(">>%s\n",(char*)Message2); -<BR> ACE_OS::fflush(stdout); - -<P> ACE_DEBUG((LM_DEBUG,"Client done reading! BYE NOW\n")); -<BR> ACE_OS::fflush(stdout); -<BR>} -<BR> - -<P>int main (int, char *[]){ -<BR>switch (ACE_OS::fork ()) -<BR> { -<BR> case -1: -<BR> ACE_ERROR_RETURN ((LM_ERROR, "%p\n", -"fork"), 1); -<BR> case 0: -<BR> <FONT COLOR="#FF0000"> // Make sure the -server starts up first.</FONT> -<BR> ACE_OS::sleep (1); -<BR> client (); -<BR> break; -<BR> default: -<BR> server (); -<BR> break; -<BR> } -<BR> return 0; -<BR>} -<BR> -<BR> <A HREF="../Chap_4/ex01.html">Next Example</A> -</BODY> -</HTML> |