Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <malloc.h>
    __segment _bheapseg( size_t size );

Description:
    The _bheapseg function allocates a based-heap segment of at least size
    bytes.

    The argument size indicates the initial size for the heap.  The heap
    will automatically be enlarged as needed if there is not enough space
    available within the heap to satisfy an allocation request by  _bcalloc,
     _bexpand,  _bmalloc, or  _brealloc.

    The value returned by _bheapseg is the segment value or selector for the
    based heap.  This value must be saved and used as an argument to other
    based heap functions to indicate which based heap to operate upon.

    Each call to _bheapseg allocates a new based heap.

Returns:
    The value returned by _bheapseg is the segment value or selector for the
    based heap.  This value must be saved and used as an argument to other
    based heap functions to indicate which based heap to operate upon.  A
    special value of  _NULLSEG is returned if the segment could not be
    allocated.

See Also:
    _bfreeseg, calloc Functions, _expand Functions, malloc Functions, realloc Functions

Example:
    #include <stdio.h>
    #include <stdlib.h>
    #include <malloc.h>

    struct list {
        struct list __based(__self) *next;
        int         value;
    };

    void main()
      {
        int         i;
        __segment   seg;
        struct list __based(seg) *head;
        struct list __based(seg) *p;

        /* allocate based heap */
        seg = _bheapseg( 1024 );
        if( seg == _NULLSEG ) {
          printf( "Unable to allocate based heap\n" );
          exit( 1 );
        }

        /* create a linked list in the based heap */
        head = 0;
        for( i = 1; i < 10; i++ ) {
          p = _bmalloc( seg, sizeof( struct list ) );
          if( p == _NULLOFF ) {
            printf( "_bmalloc failed\n" );
            break;
          }
          p->next = head;
          p->value = i;
          head = p;
        }

        /* traverse the linked list, printing out values */
        for( p = head; p != 0; p = p->next ) {
          printf( "Value = %d\n", p->value );
        }

        /* free all the elements of the linked list */
        for( ; p = head; ) {
          head = p->next;
          _bfree( seg, p );
        }
        /* free the based heap */
        _bfreeseg( seg );
      }

Classification:
    WATCOM

Systems:
    DOS/16, Win/16, QNX/16, OS/2 1.x(all)

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson