home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / MMALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.9 KB  |  61 lines

  1. /**
  2. *
  3. * Name        mmalloc -- Allocate memory outside of program
  4. *        (Formerly called PCALLOC.)
  5. *
  6. * Synopsis    ercode = mmalloc(request,pseg,psize);
  7. *
  8. *        int ercode      Returned error code
  9. *        unsigned request  Number of paragraphs requested
  10. *        unsigned *pseg      Segment address of allocated block
  11. *        unsigned *psize   Size in paragraphs of allocated block
  12. *
  13. * Description    MMALLOC allocates a block of memory.  The requested size
  14. *        of the block is specified by "request" in units called
  15. *        paragraphs (16 bytes).    The next (higher in memory)
  16. *        available block of memory is allocated and the starting
  17. *        segment address is returned.  If more memory is
  18. *        requested than is available, the amount of available
  19. *        memory is returned, but no block is actually allocated.
  20. *
  21. *        Use MMFREE to release the allocated memory back to DOS.
  22. *        Use MMSETBLK to request that the block of memory be
  23. *        grown or shrunk.
  24. *
  25. * Returns    ercode          Returned DOS error code.
  26. *        *pseg          Segment address of memory block allocated.
  27. *        *psize          Size (in paragraphs) of memory block which
  28. *                  is allocated, or (if requested amount
  29. *                  of memory is too large) the available
  30. *                  memory size.
  31. *
  32. * Version    3.0  (C)Copyright Blaise Computing Inc.  1983, 1984, 1986
  33. *
  34. **/
  35.  
  36. #include <bmemory.h>
  37. #include <butility.h>
  38.  
  39. int mmalloc(request,pseg,psize)
  40. unsigned request,*pseg,*psize;
  41. {
  42.     DOSREG dos_reg;
  43.     int    ercode;
  44.  
  45.     dos_reg.ax = 0x4800;
  46.     dos_reg.bx = request;
  47.     ercode     = dos(&dos_reg);       /* Invoke DOS function 0x48h    */
  48.     *pseg      = 0xffff;          /* Initialize to bad address    */
  49.     if (ercode == 0)
  50.     {
  51.     *pseg  = dos_reg.ax;          /* Segment address          */
  52.     *psize = dos_reg.bx;          /* Segment size              */
  53.     }
  54.     else if (ercode == 8)
  55.     *psize = dos_reg.bx;          /* Insufficient memory          */
  56.     else
  57.     *psize = 0;
  58.  
  59.     return(ercode);
  60. }
  61.