---
name: "ACE_Shared_Memory_Pool"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_Shared_Memory_Pool"
---

# ACE\_Shared\_Memory\_Pool(3)

Make a memory pool that is based on System V shared memory (shmget(2) etc.). This implementation allows memory to be shared between processes.

## NAME

ACE\_Shared\_Memory\_Pool -  Make a memory pool that is based on System V shared memory ([shmget(2)](/shmget/2.md) etc.).  This implementation allows memory to be shared between processes.

## SYNOPSIS

```
#include <ace/ACE_Memory_Pool.h>
class ACE_Shared_Memory_Pool : public ACE_Event_Handler
{
  public:
    typedef ACE_Shared_Memory_Pool_Options OPTIONS;
    ACE_Shared_Memory_Pool (
        LPCTSTR backing_store_name = 0,
        const OPTIONS *options = 0
        );
    virtual ~ACE_Shared_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 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 &offset
        );
    struct SHM_TABLE
    {
      public:
        key_t key_;
        int shmid_;
        int used_;
    };
```

    void \*base\_addr\_;     size\_t file\_perms\_;     size\_t max\_segments\_;     off\_t minimum\_bytes\_;     size\_t segment\_size\_;     key\_t base\_shm\_key\_;     virtual int find\_seg (\
         const void \*const searchPtr,\
         off\_t &offset,\
         size\_t &counter\
         );     virtual int in\_use (off\_t &offset, size\_t &counter);     ACE\_Sig\_Handler signal\_handler\_;     virtual int handle\_signal (int signum, siginfo\_t \*, ucontext\_t \*); };

## Keeps track of all the segments being used.

```
void *base_addr_;
```

Base address of the shared memory segment.  If this has the value of 0 then the OS is free to select any address, otherwise this value is what the OS must try to use to map the shared memory segment.

```
size_t file_perms_;
```

File permissions to use when creating/opening a segment.

```
size_t max_segments_;
```

Number of shared memory segments in the SHM\_TABLE table.

```
off_t minimum_bytes_;
```

What the minimim bytes of the initial segment should be.

```
size_t segment_size_;
```

Shared memory segment size.

```
key_t base_shm_key_;
```

Base shared memory key for the segment.

```
virtual int find_seg (
    const void *const searchPtr,
    off_t &offset,
    size_t &counter
    );
```

find the segment that contains the searchPtr

```
virtual int in_use (off_t &offset, size_t &counter);
```

Determine how much memory is currently in use.

```
ACE_Sig_Handler signal_handler_;
```

Handles SIGSEGV.

```
virtual int handle_signal (int signum, siginfo_t *, ucontext_t *);
```

Handle SIGSEGV and SIGBUS signals to remap shared memory properly.

## AUTHOR

Doug Schmidt and Prashant Jain

## LIBRARY

ace
