3 //=============================================================================
5 * @file Shared_Memory_MM.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
11 #ifndef ACE_SHARED_MALLOC_MM_H
12 #define ACE_SHARED_MALLOC_MM_H
13 #include /**/ "ace/pre.h"
15 #include "ace/Shared_Memory.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "ace/Mem_Map.h"
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
26 * @class ACE_Shared_Memory_MM
28 * @brief Shared memory wrapper based on MMAP.
30 * This class provides a very simple-minded shared memory manager. We
31 * strongly recommend that you do NOT use this class. Instead, please
32 * use @c ACE_Malloc, which has much more powerful capabilities.
34 class ACE_Export ACE_Shared_Memory_MM
: public ACE_Shared_Memory
37 /// Default constructor.
38 ACE_Shared_Memory_MM ();
41 ACE_Shared_Memory_MM (ACE_HANDLE handle
,
42 size_t length
= static_cast<size_t> (-1),
44 int share
= ACE_MAP_PRIVATE
,
49 ACE_Shared_Memory_MM (const ACE_TCHAR
*file_name
,
50 size_t length
= static_cast<size_t> (-1),
51 int flags
= O_RDWR
| O_CREAT
,
52 int mode
= ACE_DEFAULT_FILE_PERMS
,
54 int share
= ACE_MAP_SHARED
,
55 char *addr
= 0, ACE_OFF_T pos
= 0);
58 int open (ACE_HANDLE handle
,
59 size_t length
= static_cast<size_t> (-1),
61 int share
= ACE_MAP_PRIVATE
,
66 int open (const ACE_TCHAR
*file_name
,
67 size_t length
= static_cast<size_t> (-1),
68 int flags
= O_RDWR
| O_CREAT
,
69 int mode
= ACE_DEFAULT_FILE_PERMS
,
71 int share
= ACE_MAP_SHARED
,
75 /// Return the name of file that is mapped (if any).
76 const ACE_TCHAR
*filename () const;
78 /// Close down the shared memory segment.
81 /// Remove the shared memory segment and the underlying file.
82 virtual int remove ();
84 // = Allocation and deallocation methods.
85 /// Create a new chuck of memory containing @a size bytes.
86 virtual void *malloc (size_t size
= 0);
88 /// Free a chuck of memory allocated by
89 /// ACE_Shared_Memory_MM::malloc.
90 virtual int free (void *p
);
92 /// Return the size of the shared memory segment.
93 virtual size_t get_segment_size () const;
95 /// Return the ID of the shared memory segment (i.e., an ACE_HANDLE).
96 virtual ACE_HANDLE
get_id () const;
98 /// Dump the state of an object.
101 /// Declare the dynamic allocation hooks.
102 ACE_ALLOC_HOOK_DECLARE
;
105 /// This version is implemented with memory-mapped files.
106 ACE_Mem_Map shared_memory_
;
109 ACE_END_VERSIONED_NAMESPACE_DECL
111 #if defined (__ACE_INLINE__)
112 #include "ace/Shared_Memory_MM.inl"
113 #endif /* __ACE_INLINE__ */
115 #include /**/ "ace/post.h"
116 #endif /* ACE_SHARED_MALLOC_MM_H */