home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classes.lha / Classes / Exec / Memory.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  3.0 KB  |  131 lines

  1. #ifndef CPP_EXEC_MEMORY_H
  2. #define CPP_EXEC_MEMORY_H
  3.  
  4. // Klassen zum Umgang mit dem Heap, Systemspeicher und Memorypools
  5. //
  6. // Autor: Jochen Becher
  7. //
  8. // Historie:
  9. //
  10. // Version 1.0 am 25. Juni 94
  11.  
  12. #ifndef _INCLUDE_STDDEF_H
  13. #include <stddef.h>
  14. #endif
  15.  
  16. #ifndef EXEC_MEMORY_H
  17. #include <exec/memory.h>
  18. #endif
  19.  
  20. #ifndef CPP_EXEC_LISTS_H
  21. #include <classes/exec/lists.h>
  22. #endif
  23.  
  24. #ifndef CPP_EXEC_SHARE_H
  25. #include <classes/exec/share.h>
  26. #endif
  27.  
  28. #ifndef CPP_DATASTRUCTURES_GENARRAYLIST_H
  29. #include <classes/datastructures/genarraylist.h>
  30. #endif
  31.  
  32. class PoolListC : public ListC {
  33. public:
  34.     PoolListC();
  35.     ~PoolListC();
  36. };
  37.  
  38. class PublicHeapC {
  39. public:
  40.     static void *operator new(size_t bytes);
  41.     static void operator delete(void *object, size_t bytes);
  42. private:
  43.     static PoolListC pool;
  44. };
  45.  
  46. // ******************************************************************
  47.  
  48. class MemoryC : protected ShareManualC {
  49. public:
  50.     MemoryC() throw (MemoryX);
  51.     MemoryC(const MemoryC &);
  52.     ~MemoryC();
  53.     APTR memory() const { return mMemory; };
  54.     ULONG size() const { return mSize; };
  55.     MemoryC &operator= (const MemoryC &);
  56.     APTR allocate(ULONG bytes, ULONG flags = MEMF_ANY) throw (MemoryX);
  57.     VOID free();
  58.     ULONG available(ULONG flags = MEMF_ANY);
  59. private:
  60.     APTR mMemory;
  61.     ULONG mSize;
  62. };
  63.  
  64. class ChipMemoryC : public MemoryC {
  65. public:
  66.     ChipMemoryC() throw (MemoryX)
  67.         : MemoryC() { };
  68.     APTR allocate(ULONG bytes, ULONG flags = MEMF_ANY) throw (MemoryX)
  69.         { return MemoryC::allocate(bytes,MEMF_CHIP|flags); };
  70.     ULONG available(ULONG flags = MEMF_ANY)
  71.         { return MemoryC::available(MEMF_CHIP|flags); };
  72. };
  73.  
  74. class PublicMemoryC : public MemoryC {
  75. public:
  76.     PublicMemoryC() throw (MemoryX)
  77.         : MemoryC() { };
  78.     APTR allocate(ULONG bytes, ULONG flags = MEMF_ANY) throw (MemoryX)
  79.         { return MemoryC::allocate(bytes,MEMF_PUBLIC|flags); };
  80.     ULONG available(ULONG flags = MEMF_ANY)
  81.         { return MemoryC::available(MEMF_PUBLIC|flags); };
  82. };
  83.  
  84. class PublicChipMemoryC : public MemoryC {
  85. public:
  86.     PublicChipMemoryC() throw (MemoryX)
  87.         : MemoryC() { };
  88.     APTR allocate(ULONG bytes, ULONG flags = MEMF_ANY) throw (MemoryX)
  89.         { return MemoryC::allocate(bytes,MEMF_PUBLIC|MEMF_CHIP|flags); };
  90.     ULONG available(ULONG flags = MEMF_ANY)
  91.         { return MemoryC::available(MEMF_PUBLIC|MEMF_CHIP|flags); };
  92. };
  93.  
  94. // ******************************************************************
  95.  
  96. class MemoryPoolC : protected ListC {
  97. public:
  98.     MemoryPoolC(ULONG flags = MEMF_ANY, ULONG poolsize = 65536);
  99.     ~MemoryPoolC();
  100.     VOID changePoolsize(ULONG poolsize);
  101.     APTR allocate(ULONG bytes) throw (MemoryX);
  102.     VOID free(APTR address, ULONG bytes);
  103. private:
  104.     ULONG mflags;
  105.     ULONG psize;
  106. };
  107.  
  108. // *************************************************************
  109.  
  110. struct SmallMemoryBlock {
  111.     APTR memory;
  112.     ULONG size;
  113.     ULONG full;
  114. };
  115.  
  116. class SmallMemoryPoolC {
  117. public:
  118.     SmallMemoryPoolC(ULONG flags = MEMF_ANY, ULONG poolsize = 16384) throw (MemoryX);
  119.     ~SmallMemoryPoolC();
  120.     APTR allocate(ULONG bytes) throw (MemoryX);
  121.     VOID free(APTR address, ULONG bytes);
  122.     VOID flush() throw (MemoryX);
  123. private:
  124.     gen_arraylist pools;
  125.     struct SmallMemoryBlock *pool;
  126.     ULONG mflags;
  127.     ULONG psize;
  128. };
  129.  
  130. #endif
  131.