找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 4218|回复: 1

求教 ACE EXAMPLE 编译无法通过

[复制链接]
发表于 2008-1-17 18:40:14 | 显示全部楼层 |阅读模式
我在VC 2003下编译无法通过 说ACE_SHARED_MEMORY_POOL 找不到。求教
感激不尽
  1. #include "stdafx.h"
  2. #include "ace/Shared_Memory_MM.h"
  3. #include "ace/Shared_Memory_Pool.h"
  4. #include "ace/Malloc.h"
  5. #include "ace/Malloc_T.h"
  6. #include "ace/Memory_Pool.h"
  7. #include "ace/Malloc.h"
  8. #include "ace/LOG_MSG.H"
  9. #include "ace/Synch.h"
  10. #include "ace/Thread.h"
  11. #define DATA_SIZE 100
  12. #define MESSAGE1 "Hiya over there client process"
  13. #define MESSAGE2  "Did you hear me the first time?"
  14. LPCTSTR poolname="My_Pool";
  15. typedef ACE_Malloc<ACE_SHARED_MEMORY_POOL,ACE_Null_Mutex> Malloc_Allocator;
  16. static void server (void){
  17.     //Create the memory allocator passing it the shared memory
  18.     //pool that you want to use
  19.     Malloc_Allocator shm_allocator(poolname);
  20.     //Create a message, allocate memory for it and bind it with
  21.     //a name so that the client can the find it in the memory
  22.     //pool
  23.     char* Message1=(char*)shm_allocator.malloc(strlen(MESSAGE1));
  24.     ACE_OS::strcpy(Message1,MESSAGE1);
  25.     shm_allocator.bind("FirstMessage",Message1);
  26.     ACE_DEBUG((LM_DEBUG,"<<%s\n",Message1));
  27.     //How about a second message
  28.     char* Message2=(char*)shm_allocator.malloc(strlen(MESSAGE2));
  29.     ACE_OS::strcpy(Message2,MESSAGE2);
  30.     shm_allocator.bind("SecondMessage",Message2);
  31.     ACE_DEBUG((LM_DEBUG,"<<%s\n",Message2));
  32.     //Set the Server to go to sleep for a while so that the client has
  33.     //a chance to do its stuff
  34.     ACE_DEBUG((LM_DEBUG,
  35.         "Server done writing.. going to sleep zzz..\n\n\n"));
  36.     ACE_OS::sleep(2);
  37.     //Get rid of all resources allocated by the server. In other
  38.     //words get rid of the shared memory pool that had been
  39.     //previously allocated
  40.     shm_allocator.remove();
  41. }
  42. static void client(void){
  43.     //Create a memory allocator. Be sure that the client passes
  44.     // in the "right" name here so that both the client and the
  45.     //server use the same memory pool. We wouldnt want them to
  46.     // BOTH create different underlying pools.
  47.     Malloc_Allocator shm_allocator(poolname);
  48.     //Lets get that first message. Notice that the find is looking up the
  49.     //memory based on the "name" that was bound to it by the server.
  50.     void *Message1;
  51.     if(shm_allocator.find("FirstMessage",Message1)==-1){
  52.         ACE_ERROR((LM_ERROR,
  53.             "Client: Problem cant find data that server has sent\n"));
  54.         ACE_OS::exit(1);
  55.     }
  56.     ACE_OS::printf(">>%s\n",(char*) Message1);
  57.     ACE_OS::fflush(stdout);
  58.     //Lets get that second message now.
  59.     void *Message2;
  60.     if(shm_allocator.find("SecondMessage",Message2)==-1){
  61.         ACE_ERROR((LM_ERROR,"Client: Problem cant find data that server has sent\n"));
  62.         ACE_OS::exit(1);
  63.     }
  64.     ACE_OS::printf(">>%s\n",(char*)Message2);
  65.     ACE_OS::fflush(stdout);
  66.     ACE_DEBUG((LM_DEBUG,"Client done reading! BYE NOW\n"));
  67.     ACE_OS::fflush(stdout);
  68. }
  69. int main (int, char *[]){
  70.     switch (ACE_OS::fork ())
  71.     {
  72.     case -1:
  73.         ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "fork"), 1);
  74.     case 0:
  75.         // Make sure the server starts up first.
  76.         ACE_OS::sleep (1);
  77.         client ();
  78.         break;
  79.     default:
  80.         server ();
  81.         break;
  82.     }
  83.     return 0;
  84. }
复制代码
 楼主| 发表于 2008-1-17 18:40:21 | 显示全部楼层
加入以下头文件

#include "ace/Null_Mutex.h"
#include  "ace/MMAP_Memory_Pool.h"

example错误还真是多
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-11-22 14:18 , Processed in 0.024406 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表