1 #ifndef SRC_NODE_MEM_H_ 2 #define SRC_NODE_MEM_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include <cstddef> 7 8 namespace node { 9 namespace mem { 10 11 // Both ngtcp2 and nghttp2 allow custom allocators that 12 // follow exactly the same structure and behavior, but 13 // use different struct names. To allow for code re-use, 14 // the NgLibMemoryManager template class can be used for both. 15 16 struct NgLibMemoryManagerBase { 17 virtual void StopTrackingMemory(void* ptr) = 0; 18 }; 19 20 template <typename Class, typename AllocatorStructName> 21 class NgLibMemoryManager : public NgLibMemoryManagerBase { 22 public: 23 // Class needs to provide these methods: 24 // void CheckAllocatedSize(size_t previous_size) const; 25 // void IncreaseAllocatedSize(size_t size); 26 // void DecreaseAllocatedSize(size_t size); 27 // Environment* env() const; 28 29 AllocatorStructName MakeAllocator(); 30 31 void StopTrackingMemory(void* ptr) override; 32 33 private: 34 static void* ReallocImpl(void* ptr, size_t size, void* user_data); 35 static void* MallocImpl(size_t size, void* user_data); 36 static void FreeImpl(void* ptr, void* user_data); 37 static void* CallocImpl(size_t nmemb, size_t size, void* user_data); 38 }; 39 40 } // namespace mem 41 } // namespace node 42 43 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 44 45 #endif // SRC_NODE_MEM_H_ 46