Typed memory

Updated: April 19, 2023

Your system's startup program can reserve memory pools to be used for special purposes, such as graphics. These pools are separate from SYSRAM.

The Typed memory section in the “Interprocess Communication” chapter of the System Architecture gives an overview of typed memory and how to set up and use it. This section describes how to program with typed memory.

In order to open a typed memory object, call posix_typed_mem_open():

int posix_typed_mem_open( const char *name,
                          int oflag,
                          int tflag);

Any process with the PROCMGR_AID_MEM_PHYS ability that covers the entire address range of the object has read and write access to the memory.

The tflag argument specifies how the typed memory object behaves when mapped, and must be at most one of:

POSIX_TYPED_MEM_ALLOCATE
Allocate on mmap().
POSIX_TYPED_MEM_ALLOCATE_CONTIG
Allocate contiguously on mmap().
POSIX_TYPED_MEM_MAP_ALLOCATABLE
Map on mmap() without affecting the availability for allocation.

If you specify 0 for tflag, then mmap() maps an application-chosen area from the specified typed memory pool, and the mapped area is unavailable for allocation until all processes unmap it.

If it's successful, posix_typed_mem_open() returns a file descriptor for the typed memory object.

You can retrieve the size of an object by using posix_typed_mem_get_info(). This function fills in a posix_typed_mem_info structure, which includes the posix_tmi_length field, which contains the size of the typed memory object.

As specified by POSIX, the length field is dynamic and contains the current allocatable size for that object (in effect, the free size of the object for POSIX_TYPED_MEM_ALLOCATE and POSIX_TYPED_MEM_ALLOCATE_CONTIG). If you opened the object with a tflag of 0 or POSIX_TYPED_MEM_MAP_ALLOCATABLE, the length field is set to zero.

Once you have a file descriptor from posix_typed_mem_open(), you have a choice:

We'll look at these methods in the sections that follow.

Memory that's mapped from a typed-memory file descriptor is implicitly locked. Shared memory objects that are populated with shm_ctl() are implicitly locked, unless you use the SHMCTL_LAZY flag.