home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / dpmi / clib / dospool.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-24  |  630 b   |  35 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4. #include "dpmish.h"
  5. #include "dospool.h"
  6.  
  7. DosMemoryPool::DosMemoryPool(unsigned sz)
  8. {
  9.     int nSegs = sz/16;
  10.     if (Dpmi.allocateDosMemory(nSegs, dosseg, selector)!=DPMI_OK) {
  11.         Dpmi.fail("cannot allocate dos memory");
  12.     }
  13.     nextalloc = 0;
  14. }
  15. DosMemoryPool::~DosMemoryPool()
  16. {
  17.     if (selector)
  18.         Dpmi.freeDosMemory(selector);
  19.     selector = 0;
  20. }
  21.  
  22.  
  23. void *DosMemoryPool::allocate(size_t sz)
  24. {
  25.     void *p;
  26.     FP_SEG(p) = selector;
  27.     FP_OFF(p) = nextalloc;
  28.  
  29.     // round up to nearest longword
  30.     sz += 3;
  31.     sz -= (sz&3);
  32.     nextalloc += sz;
  33.     return p;
  34. }
  35.