mmap(2)
. This
implementation allows memory to be shared between processes.
#include <ace/ACE_Memory_Pool.h>
class ACE_MMAP_Memory_Pool : public ACE_Event_Handler {
public:
typedef ACE_MMAP_Memory_Pool_Options OPTIONS;
ACE_MMAP_Memory_Pool ( LPCTSTR backing_store_name = 0, const OPTIONS *options = 0 );
virtual ~ACE_MMAP_Memory_Pool (void);
virtual void *init_acquire ( size_t nbytes, size_t &rounded_bytes, int &first_time );
virtual void *acquire (size_t nbytes, size_t &rounded_bytes);
virtual int release (void);
virtual int sync (ssize_t len = -1, int flags = MS_SYNC);
virtual int sync (void *addr, size_t len, int flags = MS_SYNC);
virtual int protect (ssize_t len = -1, int prot = PROT_RDWR);
virtual int protect ( void *addr, size_t len, int prot = PROT_RDWR );
virtual int remap (void *addr);
virtual void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
protected:
virtual size_t round_up (size_t nbytes);
virtual int commit_backing_store_name ( size_t rounded_bytes, off_t &map_size );
virtual int map_file (off_t map_size);
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
ACE_Sig_Handler signal_handler_;
ACE_Mem_Map mmap_;
void *base_addr_;
int flags_;
int write_each_page_;
off_t minimum_bytes_;
TCHAR backing_store_name_[MAXPATHLEN + 1];
int guess_on_fault_;
LPSECURITY_ATTRIBUTES sa_;
};
ACE_MMAP_Memory_Pool (
LPCTSTR backing_store_name = 0,
const OPTIONS *options = 0
);
virtual ~ACE_MMAP_Memory_Pool (void);
virtual void *init_acquire (
size_t nbytes,
size_t &rounded_bytes,
int &first_time
);
virtual void *acquire (size_t nbytes, size_t &rounded_bytes);
nbytes
from the memory pool. rounded_bytes
is the actual number of bytes allocated. Also acquires an
internal semaphore that ensures proper serialization of
ACE_MMAP_Memory_Pool
initialization across processes.
virtual int release (void);
virtual int sync (ssize_t len = -1, int flags = MS_SYNC);
this-
base_addr_.
virtual int sync (void *addr, size_t len, int flags = MS_SYNC);
addr_
.
virtual int protect (ssize_t len = -1, int prot = PROT_RDWR);
prot
starting at this-
base_addr_ up to len
bytes. If len
== -1
then change protection of all pages in the mapped region.
virtual int protect (void *addr, size_t len, int prot = PROT_RDWR);
prot
starting at addr
up to len
bytes.
virtual int remap (void *addr);
addr
is now
covered by the address mapping. The method succeeds and returns
0 if the backing store has adequate memory to cover this address.
Otherwise, it returns -1. This method is typically called by a
UNIX signal handler for SIGSEGV or a Win32 structured exception
when another process has grown the backing store (and its
mapping) and our process now incurs a fault because our mapping
isn't in range (yet).
virtual void dump (void) const;
ACE_ALLOC_HOOK_DECLARE;
virtual size_t round_up (size_t nbytes);
virtual int commit_backing_store_name (
size_t rounded_bytes,
off_t &map_size
);
map_size
of the backing store and commit the
memory.
virtual int map_file (off_t map_size);
map_size
bytes.
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
ACE_Sig_Handler signal_handler_;
ACE_Mem_Map mmap_;
void *base_addr_;
int flags_;
ACE_OS::mmap
.
int write_each_page_;
off_t minimum_bytes_;
TCHAR backing_store_name_[MAXPATHLEN + 1];
int guess_on_fault_;
LPSECURITY_ATTRIBUTES sa_;