jvmem.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 JVMEM_HPP
  14. #define JVMEM_HPP
  15. #include "jiface.hpp"
  16. interface IVMAllocator: extends IInterface
  17. {
  18. virtual void *alloc(size32_t sz)=0; // allocates multiples of VMPAGESIZE (i.e. rounds up)
  19. virtual bool dealloc(void *p,size32_t sz)=0; // size must be the size allocated
  20. virtual offset_t allocated() const = 0; // total allocated
  21. };
  22. #define VMPAGESIZE (0x1000)
  23. #define VMPAGEMASK (VMPAGESIZE-1)
  24. #define VMPAGEROUND(s) (((s)+VMPAGEMASK)&~VMPAGEMASK)
  25. extern jlib_decl IVMAllocator *createVMAllocator(const char *_filename,offset_t size);
  26. class jlib_decl CVMLargeMemoryAllocator: public CLargeMemoryAllocator
  27. {
  28. virtual void allocchunkmem();
  29. virtual void disposechunkmem();
  30. Linked<IVMAllocator> vm;
  31. public:
  32. CVMLargeMemoryAllocator(
  33. IVMAllocator *vm,
  34. size32_t _totalmax,
  35. size32_t _chunkmin,
  36. bool _throwexception);
  37. virtual ~CVMLargeMemoryAllocator() { reset(); } // call reset before destroyed!
  38. };
  39. #endif