home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSSRC.ZIP / MEMMGR.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  2KB  |  59 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  MEMMGR.CPP                                                            */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __STDTEMPL_H )
  11. #include <StdTempl.h>
  12. #endif    // __STDTEMPL_H
  13.  
  14. #if !defined( __CHECKS_H )
  15. #include <Checks.h>
  16. #endif    // __CHECKS_H
  17.  
  18. #if !defined( __MEMMGR_H )
  19. #include <MemMgr.h>
  20. #endif    // __MEMMGR_H
  21.  
  22. unsigned max( unsigned, unsigned );
  23.  
  24. int BaseMemBlocks::allocBlock( size_t sz )
  25. {
  26.     BlockList _FAR *temp = new( max(sz,blockSize) ) BlockList( curBlock-1 );
  27.     if( temp == 0 )
  28.         return 0;
  29.     curBlock = temp+1;
  30.     blockCount++;
  31.     return 1;
  32. }
  33.  
  34. void BaseMemBlocks::freeTo( unsigned term )
  35. {
  36.     PRECONDITION( blockCount >= term );
  37.     while( blockCount > term )
  38.         {
  39.         BlockList _FAR *temp = curBlock-1;
  40.         curBlock = (temp->next)+1;
  41.         delete temp;
  42.         blockCount--;
  43.         }
  44. }
  45.  
  46. void _FAR *MemStack::allocate( size_t sz )
  47. {
  48.     sz = max( 1, sz );
  49.     if( sz > blockSize - curLoc )
  50.         if( allocBlock( sz ) == 0 )
  51.             return 0;
  52.         else
  53.             curLoc = 0;
  54.     void _FAR *temp = block() + curLoc;
  55.     curLoc += sz;
  56.     return temp;
  57. }
  58.  
  59.