---
name: "rtapi_shmem"
section: "3rtapi"
platform: "linux"
package: "linuxcnc-uspace-dev"
version: "1:2.9.4-2+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rtapi_shmem"
---

# rtapi\_shmem(3rtapi)

Functions for managing shared memory blocks

## NAME

rtapi\_shmem - Functions for managing shared memory blocks

## SYNTAX

 int rtapi\_shmem\_new(int *key*, int *module\_id*, unsigned long int *size*)

 int rtapi\_shmem\_delete(int *shmem\_id*, int *module\_id*)

 int rtapi\_shmem\_getptr(int *shmem\_id*, void \*\* *ptr*)

## ARGUMENTS

- *key*

  Identifies the memory block.  Key must be nonzero.  All modules wishing to use the same memory must use the same key.

- *module\_id*

  Module identifier returned by a prior call to **rtapi\_init**.

- *size*

  The desired size of the shared memory block, in bytes

- *ptr*

  The pointer to the shared memory block.  Note that the block may be mapped at a different address for different modules.

## DESCRIPTION

**rtapi\_shmem\_new** allocates a block of shared memory.  *key* identifies the memory block, and must be non-zero.  All modules wishing to access the same memory must use the same key. *module\_id* is the ID of the module that is making the call (see rtapi\_init).  The block will be at least *size* bytes, and may be rounded up.  Allocating many small blocks may be very wasteful. When a particular block is allocated for the first time, the contents are zeroed.  Subsequent allocations of the same block by other modules or processes will not touch the contents of the block.  Applications can use those bytes to see if they need to  initialize the block, or if another module already did so. On success, it returns a positive integer ID, which is used for all subsequent calls dealing with the block.  On failure it  returns a negative error code.

**rtapi\_shmem\_delete** frees the shared memory block associated with *shmem\_id*.  *module\_id* is the ID of the calling module. Returns a status code.

**rtapi\_shmem\_getptr** sets *\*ptr* to point to shared memory block associated with *shmem\_id*.

## REALTIME CONSIDERATIONS

**rtapi\_shmem\_getptr** may be called from non-realtime code, init/cleanup code, or realtime tasks.

**rtapi\_shmem\_new** and **rtapi\_shmem\_dete** may not be called from realtime tasks.

## RETURN VALUE
