home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / t / triq.zip / GMEM.H < prev    next >
Text File  |  1991-09-10  |  3KB  |  69 lines

  1. /*
  2.  * GMEM.H - Macros for windows 3.0 memory management in protected mode
  3.  *
  4.  * because windows 3.0 runs in pmode GlobalLock and GlobalUnlock are
  5.  * unnessary.  The "Selector" to a memory object will always be the
  6.  * same for the life of the memory object.
  7.  *
  8.  * these macros take advantage of the following win3 memory "facts"
  9.  *
  10.  *      a SELECTOR (to a global object) is a HANDLE
  11.  *      a HANDLE is *not* a SELECTOR!!!!!!!!
  12.  *
  13.  *      GlobalLock() and GlobalUnlock() do *not* keep lock counts
  14.  *
  15.  *      GlobalLock() is the only way to convert a HANDLE to a SELECTOR
  16.  *
  17.  * functions:
  18.  *
  19.  *      GHandle(sel)                convert a SELECTOR to a HANDLE
  20.  *      GSelector(h)                convert a HANDLE to a SELECTOR
  21.  *
  22.  *      GAllocSel(ulBytes)          allocate a SELECTOR ulBytes in size
  23.  *      GAllocPtr(ulBytes)          allocate a POINTER ulBytes in size
  24.  *
  25.  *      GReAllocSel(sel,ulBytes)    re-alloc a SELECTOR
  26.  *      GReAllocPtr(lp,ulBytes)     re-alloc a POINTER
  27.  *
  28.  *      GSizeSel(sel)               return the size in bytes of a SELECTOR
  29.  *
  30.  *      GLockSel(sel)               convert a SELECTOR into a POINTER
  31.  *      GUnlockSel(sel)             does nothing
  32.  *
  33.  *      GFreeSel(sel)               free a SELECTOR
  34.  *      GFreePtr(lp)                free a POINTER
  35.  *
  36.  *
  37.  */
  38.  
  39. HANDLE __H;
  40.  
  41. #define MAKEP(sel,off)      ((LPVOID)MAKELONG(off,sel))
  42.  
  43. #define GHandle(sel)        ((HANDLE)(sel))  /* GlobalHandle? */
  44. #define GSelector(h)        (HIWORD((DWORD)GlobalLock(h)))
  45.  
  46. #define GAllocSelF(f,ulBytes) ((__H=GlobalAlloc(f,(LONG)(ulBytes))) ? GSelector(__H) : NULL )
  47. #define GAllocPtrF(f,ulBytes) MAKEP(GAllocSelF(f,ulBytes),0)
  48. #define GAllocF(f,ulBytes)    GAllocSelF(f,ulBytes)
  49.  
  50. #define GAllocSel(ulBytes)    GAllocSelF(GMEM_MOVEABLE,ulBytes)
  51. #define GAllocPtr(ulBytes)    GAllocPtrF(GMEM_MOVEABLE,ulBytes)
  52. #define GAlloc(ulBytes)       GAllocSelF(GMEM_MOVEABLE,ulBytes)
  53.  
  54. #define GReAllocSel(sel,ulBytes)   ((__H=GlobalReAlloc((HANDLE)(sel),(LONG)(ulBytes),0)) ? GSelector(__H) : NULL )
  55. #define GReAllocPtr(lp,ulBytes)    MAKEP(GReAllocSel(HIWORD((DWORD)(lp)),ulBytes),0)
  56. #define GReAlloc(sel,ulBytes)      GReAllocSel(sel,ulBytes)
  57.  
  58. #define GSizeSel(sel)       GlobalSize((HANDLE)(sel))
  59. #define GSize(sel)          GSizeSel(sel)
  60.  
  61. #define GLockSel(sel)       MAKEP(sel,0)
  62. #define GUnlockSel(sel)     /* nothing */
  63. #define GLock(sel)          GLockSel(sel)
  64. #define GUnlock(sel)        GUnlockSel(sel)
  65.  
  66. #define GFreeSel(sel)       (GlobalUnlock(GHandle(sel)),GlobalFree(GHandle(sel)))
  67. #define GFreePtr(lp)        GFreeSel(HIWORD((DWORD)(lp)))
  68. #define GFree(sel)          GFreeSel(sel)
  69.