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>
    void        *_expand( void *mem_blk, size_t size );
    void __based(void) *_bexpand( __segment seg,
                                  void __based(void) *mem_blk,
                                  size_t size );
    void __far  *_fexpand(void __far  *mem_blk,size_t size);
    void __near *_nexpand(void __near *mem_blk,size_t size);

Description:
    The  _expand functions change the size of the previously allocated block
    pointed to by mem_blk by attempting to expand or contract the memory
    block without moving its location in the heap.  The argument size
    specifies the new desired size for the memory block.  The contents of
    the memory block are unchanged up to the shorter of the new and old
    sizes.

    Each function expands the memory from a particular heap, as listed
    below:

    _expand
        Depends on data model of the program

    _bexpand
        Based heap specified by seg value

    _fexpand
        Far heap (outside the default data segment)

    _nexpand
        Near heap (inside the default data segment)

    In a small data memory model, the  _expand function is equivalent to the
     _nexpand function; in a large data memory model, the  _expand function
    is equivalent to the  _fexpand function.

Returns:
    The  _expand functions return the value mem_blk if it was successful in
    changing the size of the block.  The return value is NULL (_NULLOFF for
     _bexpand) if the memory block could not be expanded to the desired
    size.  It will be expanded as much as possible in this case.

    The appropriate  _msize function can be used to determine the new size
    of the expanded block.

See Also:
    calloc Functions Functions, free Functions Functions, halloc, hfree, malloc Functions Functions,
    _msize Functions Functions, realloc Functions Functions, sbrk

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

    void main()
      {
        char *buf;
        char __far *buf2;

        buf = (char *) malloc( 80 );
        printf( "Size of buffer is %u\n", _msize(buf) );
        if( _expand( buf, 100 ) == NULL ) {
            printf( "Unable to expand buffer\n" );
        }
        printf( "New size of buffer is %u\n", _msize(buf) );
        buf2 = (char __far *) _fmalloc( 2000 );
        printf( "Size of far buffer is %u\n", _fmsize(buf2) );
        if( _fexpand( buf2, 8000 ) == NULL ) {
            printf( "Unable to expand far buffer\n" );
        }
        printf( "New size of far buffer is %u\n",
                 _fmsize(buf2) );
      }

    produces the following:

    Size of buffer is 80
    Unable to expand buffer
    New size of buffer is 80
    Size of far buffer is 2000
    New size of far buffer is 8000

Classification:
    WATCOM

Systems:
     _expand - All

    _bexpand - DOS/16, Win/16, QNX/16, OS/2 1.x(all)
    _fexpand - DOS/16, Win/16, QNX/16, OS/2 1.x(all)
    _nexpand - DOS, Win, QNX, OS/2 1.x, OS/2 1.x(MT), OS/2 2.x, NT

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