[Previous]
[Contents]
[Next]

qnx_segment_alloc()

allocate a segment

Synopsis:

#include <sys/seginfo.h>
unsigned qnx_segment_alloc( long nbytes );

Description:

The qnx_segment_alloc() function allocates a segment of memory nbytes in size from the operating system. The segment is allocated from the system free space using a top-down allocation scheme. The segment is filled with zeroes. In protected mode, a local descriptor table (LDT) selector with read/write access is returned; in real mode, an 8086 segment is returned.

This function is used by the standard C memory allocators such as malloc(). It requests segments from the system in large chunks, which it then manages. You would only call this function directly if you wish to manage your own segments, perhaps for a segment that's shared between processes. In this case you must use the calls qnx_segment_arm(), qnx_segment_get(), and qnx_segment_put() to give another process access to the segment.


Note: Although this function is available in both the 16-bit and 32-bit libraries, the qnx_segment_... family of calls is primarily intended for the 16-bit segmented version of QNX. To allocate and share memory in the 32-bit version you should look at using the POSIX shm_open() and mmap() functions.

Returns:

A segment number on success. On error, it returns -1 and errno is set.

Errors:

EINVAL
The parameter nbytes is 0.
ENOMEM
Insufficient system memory to allocate the segment or insufficient local process manager memory to manage the segment.

Examples:

#include <i86.h>
#include <sys/seginfo.h>

void main()
  {
    unsigned base;
    char __far *p;

    /* Allocate a 32 Kbyte array */
    base = qnx_segment_alloc( 32768 );

    /* Point at byte 16,000 in the array */
    p = MK_FP( base, 16000 );

    /* Set the byte and read it back */
    *p = 'a';
    printf( "base = %u, p = %08lx\n", base, p );
    printf( "*p = %c\n", *p );
    qnx_segment_free( base );
  }

Classification:

QNX

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

Caveats:

Your application must run as root to call this function.

See also:

errno, qnx_segment_alloc_flags(), qnx_segment_arm(), qnx_segment_flags(), qnx_segment_free(), qnx_segment_get(), qnx_segment_huge(), qnx_segment_index(), qnx_segment_info(), qnx_segment_overlay_flags(), qnx_segment_overlay(), qnx_segment_put(), qnx_segment_raw_alloc(), qnx_segment_raw_free(), qnx_segment_realloc()

/etc/readme/technotes/shmem.txt or shmem.ps


[Previous]
[Contents]
[Next]