Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ msize(DOS) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          _msize, _fmsize, _nmsize - Return size of allocated memory
          block.

     Syntax
          #include <malloc.h>

          size_t _msize(buffer)
          void *buffer;

          size_t _fmsize(buffer)
          void far *buffer;

          size_t _nmsize(buffer)
          void near *buffer;

     Description
          The _msize family of functions returns the size, in bytes,
          of the memory block allocated by a call to calloc, malloc,
          or realloc.

          In large data models (compact- and large-model programs),
          _msize maps to _fmsize. In small data models (small- and
          medium-model programs), _msize maps to _nmsize.

          The _nmsize function returns the size (in bytes) of the
          memory block allocated by a call to _nmalloc.

          The particular _msize function returns the size in bytes of
          the indicated memory block allocated by a call to the
          corresponding malloc function. The location of the memory
          block is indicated in the table below:

            Function   Data Segment

            _msize      Depends on data model of program

            _fmsize     Far heap (outside default data segment)

            _nmsize     Near heap (inside default data segment)

     Return Value
          All three functions return the size (in bytes) as an
          unsigned integer.

     See Also
          calloc(S), _expand(DOS), malloc(DOS), realloc(S)

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

          main()
           {
                  long *oldbuffer;
                  size_t newsize = 64000;
                  oldbuffer = (long *)malloc(10000*sizeof(long));

                  /* Get size of original memory: */
                  printf("Size of memory block pointed to by oldbuffer
          = %u\n",
                          _msize(oldbuffer));

                  if (_expand(oldbuffer,newsize) != NULL)
                  /* if _expand succeeded: */
                          printf("Expand increased block to %u\n",
                                  _msize(oldbuffer));
                  else
                          /* otherwise _expand failed: */
                          printf("Expand increased block to only
          %u\n",
                                  _msize(oldbuffer));
           }

          Sample output:

            Size of memory block pointed to by oldbuffer = 40000
            Expand increased block to only 44718

          This program allocates a block of memory for  oldbuffer  and
          then uses _msize to display the size of that block. Next, it
          uses expand to expand the amount of memory used by oldbuffer
          and then calls _msize again to display the new amount of
          memory allocated to  oldbuffer.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026