allocate a huge segment


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


The qnx_segment_huge() function allocates nbytes of memory from the system. This function is similar to qnx_segment_alloc().

If the requested segment exceeds 65536 bytes, more than one segment is allocated. The value of the first segment is returned. In protected mode the segments are contiguous in the Local Descriptor Table (LDT), and separated by a value of 8. Therefore, an address is formed using the following expression:

segment = base_segment + (offset/65536 * 8);
offset  = offset % 65536;

In real mode, one large contiguous region is allocated.

Due to the complexity of writing code to deal with this, most programmers declare huge pointers in C and call halloc() and hfree().


The start segment of a list of one or more segments. On error, it returns -1, and errno is set.


Insufficient system memory to allocate the segment or insufficient local process manager memory to manage the segment.


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

#define huge_ptr( a, b ) \
    ( MK_FP( a+( b/65536*8 ), b%65536 ) )

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

    /* Allocate a 1 Megabyte array */
    base = qnx_segment_huge( 1000000 );

    /* Point at byte 500, 000 in the array */
    p = huge_ptr( base, 500000 );

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



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

See also:

errno, qnx_segment_alloc(), qnx_segment_alloc_flags(), qnx_segment_arm(), qnx_segment_flags(), qnx_segment_free(), qnx_segment_get(), 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()