jheap.ipp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef JHEAP_IPP
  14. #define JHEAP_IPP
  15. typedef unsigned long ulong;
  16. #define PAGESIZE 0x1000U //??Initialise from GetSystemInfo
  17. #define PREFERRED_HEAP_ADDRESS (void *)0x08000000
  18. #define MAXCOMMIT 0x8000000L // about 100M
  19. #define CHUNK_MAX 32
  20. #define ISCHUNKED(ptr) (((ulong)ptr - (ulong)ChunkAllocator32::lowerBound) < MAXCOMMIT)
  21. #define PTR2ALLOC(ptr) (*(Allocator32 * *)((ulong)(ptr) & ~(PAGESIZE-1)))
  22. #define FREECHUNKED(ptr) (PTR2ALLOC(ptr)->deallocate(ptr))
  23. #define MALLOCCHUNKED(size) (ChunkAllocator32::allocate(size))
  24. #define SIZEofCHUNKED(ptr) (PTR2ALLOC(ptr)->getSize())
  25. class Allocator32;
  26. class ChunkAllocator32
  27. {
  28. public:
  29. ChunkAllocator32(void);
  30. ~ChunkAllocator32(void);
  31. static char * allocatePage(void);
  32. public:
  33. static char * lowerBound;
  34. static char * upperBound;
  35. static char * curAlloc;
  36. };
  37. class Allocator32
  38. {
  39. public:
  40. Allocator32(size32_t _size, ChunkAllocator32 * _allocator);
  41. void deallocate(void * ptr);
  42. char * allocate();
  43. size32_t getSize(void) { return size; }
  44. protected:
  45. bool more(void);
  46. private:
  47. char * next;
  48. size32_t size;
  49. ChunkAllocator32 * allocator;
  50. };
  51. #endif