Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_dos_allocmem() allocate a block of memory</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_allocmem()         Allocate a block of memory

 #include   <dos.h>

  unsigned     _dos_allocmem(size, segment);
  unsigned size;         Block size requested, in 16 byte paragraphs
  unsigned *segment;     Buffer to hold return value indicating segment
                         address

    _dos_allocmem() uses MS-DOS function 48h to allocate contiguous
    blocks of memory 'size' paragraphs long. A paragraph is 16 bytes, and
    allocated segments are always aligned on segment addresses (0h offset).
    'Segment' points to the segment address for the beginning of the new
    block if the allocation was successful. If unsuccessful, it returns
    the size of the largest available block that can be allocated.

    Returns:    If the memory was successfully allocated _dos_allocmem()
                returns 0. If unsuccessful it returns the MS-DOS error
                code and sets errno to ENOMEM. The MS-DOS error code will
                be one of the following:

                    07h = memory control blocks damaged
                    08h = insufficient memory to satisfy request

      Notes:    By setting 'size' = FFFFh this function can be used to
                find the amount of available memory. The call will return
                an error, which can be ignored, since DOS cannot allocate
                more than 640k of memory.

                In MS-DOS 3.0 or higher, dosexterr() can be used for
                extended error code information.

 Portability:   MS-DOS only, version 2.0 or higher

------------------------------- Example ---------------------------------

           This program allocates 4k bytes of memory if available, or else it
           reports the maximum size block available.

           #include <dos.h>

           unsigned segment;

           main()
           {
              /* Allocate 4k block of memory (256 paragraphs) */
              if (_dos_allocmem(256, &segment))
                  /* unable to allocate block */
                  printf("Insufficient memory: only %lu bytes available\n",
                          (long) segment * (long) 16);
              else
                  printf("4k bytes allocated\n");
           }


See Also: _dos_setblock() _dos_freemem()

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