Reading values from a shared memory segment¶

read_shared_memory()

Reading values from shared memory


SYNTAX

read_shared_memory(shm_id, offset, len, options)

Read the current field values from the shared memory segment specified in shm_id into the associated record buffer. Sculptor ensures that this operation is atomic so that the function cannot read a partly updated record.

The associated record buffer was specified in the function call that created or linked to the segment.

shm_id

The return value from the function that created or linked to the segment.

offset

The byte offset within the record to start reading into. This feature is for advanced use, and should normally be set to 0.

len

The number of bytes to read. This feature is for advanced use. Set to 0 to read the entire record.

options

May be SHM_KEEP_LOCK or 0.

If options is SHM_KEEP_LOCK, Sculptor prevents other programs from writing to the shared memory segment until this program calls write_shared_memory() or read_shared_memory() with options = 0, or calls unlock_shared_memory(). It is very important to hold this lock for a short time only since, when it is set, other programs that try to access this memory segment will go into a non-responding state.

The function returns the number of bytes read.


EXAMPLE

!record Clients {
     fieldlist
}

!temp SMclient,,i4

     SMclient = create_shared_memory("shm_segjx", Clients)
     if (SMclient == 0) {
          error "Error creating shared memory segment: errno = " + tostr(sys.Errno)
          exit
     }
     ...

     read_shared_memory(SMclient, 0, 0, SHM_KEEP_LOCK)

Shared memory functions

create_shared_memory()

Create a shared memory segment

link_shared_memory()

Link to an existing shared memory segment

read_shared_memory()

Read the current field values from shared memory into associated record buffer

write_shared_memory()

Write the current values from associated record buffer into shared memory

unlock_shared_memory()

Unlock a shared memory segment

unlink_shared_memory()

Unlink a program from a shared memory segment


RELATED TOPICS

Shared memory options in sculptor.h

!record

![o]file