home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / PRRepMem.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.5 KB  |  168 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRRepMem.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef PRSHATTR_H
  13. #include "PRShAttr.h"
  14. #endif
  15.  
  16. #ifndef FWFIXMEM_H
  17. #include "FWFixMem.h"
  18. #endif
  19.  
  20. #ifdef FW_BUILD_MAC
  21. #pragma segment FW_Graphics
  22. #endif
  23.  
  24. #ifdef FW_NATIVE_EXCEPTIONS
  25.  
  26. //========================================================================================
  27. // Memory management
  28. //========================================================================================
  29.  
  30. #define FW_SUBALLOCATE
  31.  
  32. //----------------------------------------------------------------------------------------
  33. // FW_CPrivInkRep
  34. //----------------------------------------------------------------------------------------
  35.  
  36. static FW_CFixedAllocator gInkAllocator(
  37.     sizeof(FW_CPrivInkRep)
  38. #ifdef FW_DEBUG
  39.     , "FW_CPrivInkRep"
  40. #endif
  41.     );
  42.  
  43. void* FW_CPrivInkRep::operator new(size_t size)
  44. {
  45. #ifndef FW_DEBUG
  46.     FW_UNUSED(size);
  47. #endif
  48.     FW_ASSERT(size == sizeof(FW_CPrivInkRep));
  49. #ifdef FW_SUBALLOCATE
  50.     return gInkAllocator.Allocate();
  51. #else
  52.     return ::operator new(size);
  53. #endif
  54. }
  55.  
  56. void FW_CPrivInkRep::operator delete(void* p)
  57. {
  58. #ifdef FW_SUBALLOCATE
  59.     gInkAllocator.Free(p);
  60. #else
  61.     ::operator delete(p);
  62. #endif
  63. }
  64.  
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // FW_CPrivStyleRep
  68. //----------------------------------------------------------------------------------------
  69.  
  70. static FW_CFixedAllocator gStyleAllocator (
  71.     sizeof(FW_CPrivStyleRep)
  72. #ifdef FW_DEBUG
  73.     , "FW_CPrivStyleRep"
  74. #endif
  75.     );
  76.  
  77. void* FW_CPrivStyleRep::operator new(size_t size)
  78. {
  79. #ifndef FW_DEBUG
  80.     FW_UNUSED(size);
  81. #endif
  82.     FW_ASSERT(size == sizeof(FW_CPrivStyleRep));
  83. #ifdef FW_SUBALLOCATE
  84.     return gStyleAllocator.Allocate();
  85. #else
  86.     return ::operator new(size);
  87. #endif
  88. }
  89.  
  90. void FW_CPrivStyleRep::operator delete(void* p)
  91. {
  92. #ifdef FW_SUBALLOCATE
  93.     gStyleAllocator.Free(p);
  94. #else
  95.     ::operator delete(p);
  96. #endif
  97. }
  98.  
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // FW_CPrivFontRep
  102. //----------------------------------------------------------------------------------------
  103.  
  104. static FW_CFixedAllocator gFontAllocator (
  105.      sizeof(FW_CPrivFontRep)
  106. #ifdef FW_DEBUG
  107.     , "FW_CPrivFontRep"
  108. #endif
  109.     );
  110.  
  111. void* FW_CPrivFontRep::operator new(size_t size)
  112. {
  113. #ifndef FW_DEBUG
  114.     FW_UNUSED(size);
  115. #endif
  116.     FW_ASSERT(size == sizeof(FW_CPrivFontRep));
  117. #ifdef FW_SUBALLOCATE
  118.     return gFontAllocator.Allocate();
  119. #else
  120.     return ::operator new(size);
  121. #endif
  122. }
  123.  
  124. void FW_CPrivFontRep::operator delete(void* p)
  125. {
  126. #ifdef FW_SUBALLOCATE
  127.     gFontAllocator.Free(p);
  128. #else
  129.     ::operator delete(p);
  130. #endif
  131. }
  132.  
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // FW_CPrivPatternRep
  136. //----------------------------------------------------------------------------------------
  137.  
  138. #define MAX(a, b)    \
  139.     ((a) > (b)  ? (a) : (b))
  140.  
  141. static FW_CFixedAllocator gPatternAllocator (
  142.     MAX(sizeof(FW_CPrivBWPatternRep), sizeof(FW_CPrivColorPatternRep))
  143. #ifdef FW_DEBUG
  144.     , "FW_CPriv{BW|Color}PatternRep"
  145. #endif
  146.     );
  147.  
  148. void* FW_CPrivPatternRep::operator new(size_t size)
  149. {
  150. #ifdef FW_SUBALLOCATE
  151.     FW_UNUSED(size);
  152.     return gPatternAllocator.Allocate();
  153. #else
  154.     return ::operator new(size);
  155. #endif
  156. }
  157.  
  158. void FW_CPrivPatternRep::operator delete(void* p)
  159. {
  160. #ifdef FW_SUBALLOCATE
  161.     gPatternAllocator.Free(p);
  162. #else
  163.     ::operator delete(p);
  164. #endif
  165. }
  166.  
  167. #endif
  168.