Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>allocmem() allocate dos memory segment</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 allocmem()              Allocate DOS Memory Segment

 #include   <dos.h>

 int        allocmem(size,seg);
 unsigned   size;                        Size in paragraphs
 unsigned   *seg;                        Pointer to segment address

    allocmem() allocates a block of free memory with MS-DOS system call
    0x48, then returns the segment address of the memory block that was
    allocated. 'size' is the size, in paragraphs, of the requested memory
    block. 'seg' is a pointer to the word to be assigned the segment
    address of the allocated memory, assuming enough is available.  If a
    block of the requested size cannot be allocated, no assignment is
    made. Allocated blocks of memory are always paragraph aligned.

       Returns:     -1, if successful.  On error, returns a value
                    representing the size, in paragraphs, of the largest
                    available block.

         Notes:     Use freemem() to free memory allocated by allocmem().

   Portability:     MS-DOS only.

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

    The following statements try to allocate a block of 16000 bytes.  If
    16000 bytes aren't available, they allocate the largest possible
    block.

           #include <stdio.h>      /* for printf */
           #include <dos.h>        /* for allocmem */

           int maxmem;
           unsigned memseg, memsize;

           main()
           {
               if ((maxmem = allocmem(memsize = 1000,&memseg)) != -1) {
                  /*couldn't allocate, get largest available */
                   if (allocmem(memsize = maxmem,&memseg) != -1)
                       memsize = 0;
               }
               printf("%u bytes allocated\n",memsize * 16);
           }

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