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
|
// $Id$
// Test the capabilities of the ACE shared memory manager in terms of
// its ability to handle multiple mallocs rooted at different base
// addresses.
#include "ace/Malloc.h"
#include "ace/Synch.h"
ACE_RCSID(Shared_Malloc, test_multiple_mallocs, "$Id$")
typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_Process_Mutex> MALLOC;
// Default address for shared memory mapped files and SYSV shared
// memory (defaults to 64 M).
void *REQUEST_BASE_ADDR = ((void *) (64 * 1024 * 1024));
const char *REQUEST_STRING = "hello from request repository";
// Default address for shared memory mapped files and SYSV shared
// memory (defaults to 64 M).
void *RESPONSE_BASE_ADDR = ((void *) (128 * 1024 * 1024));
const char *RESPONSE_STRING = "hello from response repository";
int
main (int, char *[])
{
ACE_MMAP_Memory_Pool_Options request_options (REQUEST_BASE_ADDR);
// Create an adapter version of an allocator.
ACE_Allocator_Adapter<MALLOC> *shmem_request =
new ACE_Allocator_Adapter<MALLOC> ("request_file", "RequestLock", &request_options);
ACE_MMAP_Memory_Pool_Options response_options (RESPONSE_BASE_ADDR);
// Create a non-adapter version of an allocator.
MALLOC *shmem_response =
new MALLOC ("response_file","ResponseLock", &response_options);
void *data = 0;
if (shmem_request->find ("foo", data) == 0)
{
ACE_OS::printf ("%s\n", data);
shmem_request->remove ();
}
else
{
data = shmem_request->malloc (ACE_OS::strlen (REQUEST_STRING) + 1);
ACE_OS::strcpy ((char *) data, REQUEST_STRING);
shmem_request->bind ("foo", data);
}
data = 0;
if (shmem_response->find ("foo", data) == 0)
{
ACE_OS::printf ("%s\n", data);
shmem_response->remove ();
}
else
{
data = shmem_response->malloc (ACE_OS::strlen (RESPONSE_STRING) + 1);
ACE_OS::strcpy ((char *) data, RESPONSE_STRING);
shmem_response->bind ("foo", data);
ACE_OS::printf ("Run again to see results and release resources.\n");
}
return 0;
}
|