jmalloc.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 JMALLOC_HPP
  14. #define JMALLOC_HPP
  15. #include "jiface.hpp"
  16. interface IAllocator: extends IInterface
  17. {
  18. virtual void * allocMem(size32_t sz)=0;
  19. virtual void freeMem(void *)=0;
  20. virtual void * reallocMem(void *prev,size32_t sz)=0;
  21. virtual size32_t usableSize(const void *)=0;
  22. virtual memsize_t totalAllocated()=0; // amount allocated from OS
  23. virtual memsize_t totalMax()=0; // total that can be allocated from OS
  24. virtual memsize_t totalRemaining()=0; // maximum remaining
  25. virtual void checkPtrValid(const void * ptr)=0; // for debugging only
  26. virtual void logMemLeaks(bool logdata)=0;
  27. virtual void * allocMem2(size32_t sz, size32_t &usablesz)=0; // returns size actually allocated
  28. virtual void * reallocMem2(void *prev,size32_t sz, size32_t &usablesz)=0; // returns size actually allocated
  29. virtual size32_t roundupSize(size32_t sz)=0; // returns usable size would round up to
  30. };
  31. extern jlib_decl IAllocator *createMemoryAllocator(
  32. memsize_t maxtotal, // maximum to allocate from OS
  33. size32_t maxsuballocsize=1024, // set to 0 to disable suballocation
  34. memsize_t mintotal=0x100000*16, // above this amount free to OS
  35. bool avoidReallocFragmentation=true // whether reallocMem should avoid fragmenting memory by copying where needed
  36. );
  37. extern jlib_decl IAllocator *createGuardedMemoryAllocator( // for debug only!
  38. memsize_t maxtotal, // maximum to allocate from OS
  39. size32_t maxsuballocsize=1024, // set to 0 to disable suballocation
  40. memsize_t mintotal=0x100000*16, // above this amount free to OS
  41. bool avoidReallocFragmentation=true, // whether reallocMem should avoid fragmenting memory by copying where needed
  42. size32_t guardsize= 32
  43. );
  44. extern jlib_decl void testAllocator();
  45. #endif