home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / vm / src / dos / vheap.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-15  |  2.2 KB  |  98 lines

  1. /***
  2. *vheap.c - Virtual Heap
  3. *
  4. *       Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       Contains C wrappers for certain VM routines.
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <vmemory.h>
  12. #include <system.h>
  13. #include <vmm.h>
  14. #include <vmbm.h>
  15. #include <vmp.h>
  16.  
  17. /*
  18.  * set max allocation size such that rounded up
  19.  * it will be less than 64K.
  20.  */
  21.  
  22. #define _VM_MAXALLOC 65530
  23.  
  24.  
  25. /***
  26. * _vmalloc - Allocate a VM block
  27. *
  28. *Purpose:
  29. *       Allocate a VM block.
  30. *
  31. *       Make sure the block is smaller than the size of the DOS swap
  32. *       area (i.e., make sure any block that is allocated can be later
  33. *       loaded).
  34. *
  35. *       Then call VMBM to do all the work.
  36. *
  37. *Entry:
  38. *       size = size of block to allocate (in bytes)
  39. *
  40. *Exit:
  41. *       success: handle of block
  42. *       failure: _VM_NULL
  43. *
  44. *Exceptions:
  45. *
  46. *******************************************************************************/
  47.  
  48. _vmhnd_t _far _pascal __vmalloc(unsigned long size)
  49. {
  50.  
  51.     if ( (size > _VM_MAXALLOC) ||
  52.          (size > ((unsigned long)(((unsigned long)_cPageDos-1) * cbVmPage)))
  53.        )
  54.         return(_VM_NULL);
  55.  
  56.     return((_vmhnd_t)__HbkVmAllocate(size));
  57.  
  58. }
  59.  
  60.  
  61. /***
  62. * _vrealloc - Reallocate a VM block
  63. *
  64. *Purpose:
  65. *       Reallocate a VM block.
  66. *
  67. *       (1) Make sure the block is smaller than the size of the DOS swap
  68. *       area (i.e., make sure any block that is allocated can be later
  69. *       loaded).
  70. *
  71. *       (2) If supplied handle is not NULL, make sure block is not locked.
  72. *
  73. *       Then call VMBM to do all the work.
  74. *
  75. *Entry:
  76. *       size = size of block to allocate (in bytes)
  77. *
  78. *Exit:
  79. *       success: handle of block
  80. *       failure: _VM_NULL
  81. *
  82. *Exceptions:
  83. *
  84. *******************************************************************************/
  85.  
  86. _vmhnd_t _far _pascal __vrealloc(_vmhnd_t vhnd, unsigned long size)
  87. {
  88.  
  89.     if ( ((vhnd != _VM_NULL) && (_vlockcnt(vhnd) != 0)) ||
  90.          (size > _VM_MAXALLOC) ||
  91.          (size > ((unsigned long)(((unsigned long)_cPageDos-1) * cbVmPage)))
  92.        )
  93.         return(_VM_NULL);
  94.  
  95.     return((_vmhnd_t)__HbkVmReallocate((HBK)vhnd, size));
  96.  
  97. }
  98.