3 //=============================================================================
5 * @file Shared_Memory_MM.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
12 #ifndef ACE_SHARED_MALLOC_MM_H
13 #define ACE_SHARED_MALLOC_MM_H
14 #include /**/ "ace/pre.h"
16 #include "ace/Shared_Memory.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #include "ace/Mem_Map.h"
24 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 * @class ACE_Shared_Memory_MM
29 * @brief Shared memory wrapper based on MMAP.
31 * This class provides a very simple-minded shared memory manager. We
32 * strongly recommend that you do NOT use this class. Instead, please
33 * use @c ACE_Malloc, which has much more powerful capabilities.
35 class ACE_Export ACE_Shared_Memory_MM
: public ACE_Shared_Memory
38 /// Default constructor.
39 ACE_Shared_Memory_MM (void);
42 ACE_Shared_Memory_MM (ACE_HANDLE handle
,
43 size_t length
= static_cast<size_t> (-1),
45 int share
= ACE_MAP_PRIVATE
,
50 ACE_Shared_Memory_MM (const ACE_TCHAR
*file_name
,
51 size_t length
= static_cast<size_t> (-1),
52 int flags
= O_RDWR
| O_CREAT
,
53 int mode
= ACE_DEFAULT_FILE_PERMS
,
55 int share
= ACE_MAP_SHARED
,
56 char *addr
= 0, ACE_OFF_T pos
= 0);
59 int open (ACE_HANDLE handle
,
60 size_t length
= static_cast<size_t> (-1),
62 int share
= ACE_MAP_PRIVATE
,
67 int open (const ACE_TCHAR
*file_name
,
68 size_t length
= static_cast<size_t> (-1),
69 int flags
= O_RDWR
| O_CREAT
,
70 int mode
= ACE_DEFAULT_FILE_PERMS
,
72 int share
= ACE_MAP_SHARED
,
76 /// Return the name of file that is mapped (if any).
77 const ACE_TCHAR
*filename (void) const;
79 /// Close down the shared memory segment.
80 virtual int close (void);
82 /// Remove the shared memory segment and the underlying file.
83 virtual int remove (void);
85 // = Allocation and deallocation methods.
86 /// Create a new chuck of memory containing @a size bytes.
87 virtual void *malloc (size_t size
= 0);
89 /// Free a chuck of memory allocated by
90 /// <ACE_Shared_Memory_MM::malloc>.
91 virtual int free (void *p
);
93 /// Return the size of the shared memory segment.
94 virtual size_t get_segment_size (void) const;
96 /// Return the ID of the shared memory segment (i.e., an ACE_HANDLE).
97 virtual ACE_HANDLE
get_id (void) const;
99 /// Dump the state of an object.
100 void dump (void) const;
102 /// Declare the dynamic allocation hooks.
103 ACE_ALLOC_HOOK_DECLARE
;
106 /// This version is implemented with memory-mapped files.
107 ACE_Mem_Map shared_memory_
;
110 ACE_END_VERSIONED_NAMESPACE_DECL
112 #if defined (__ACE_INLINE__)
113 #include "ace/Shared_Memory_MM.inl"
114 #endif /* __ACE_INLINE__ */
116 #include /**/ "ace/post.h"
117 #endif /* ACE_SHARED_MALLOC_MM_H */