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 Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <malloc.h>
    int _bfreeseg( __segment seg );

Description:
    The _bfreeseg function frees a based-heap segment.

    The argument seg indicates the segment returned by an earlier call to
     _bheapseg.

Returns:
    The _bfreeseg function returns 0 if successful and -1 if an error
    occurred.

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, Windows, QNX/16, OS/2 1.x(all)

See Also:
    _bheapseg, calloc, _expand, free, malloc, realloc

See Also: _bheapseg

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