1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_LIBPANDABASE_MEM_MALLOC_MEM_POOL_H_ 17 #define PANDA_LIBPANDABASE_MEM_MALLOC_MEM_POOL_H_ 18 19 #include "mem_pool.h" 20 21 namespace panda { 22 23 // Simple Mem Pool without cache 24 class MallocMemPool : public MemPool<MallocMemPool> { 25 private: 26 template <class ArenaT = Arena> 27 ArenaT *AllocArenaImpl(size_t size, SpaceType space_type, AllocatorType allocator_type, void *allocator_addr); 28 29 template <class ArenaT = Arena> 30 void FreeArenaImpl(ArenaT *arena); 31 32 static Pool AllocPoolImpl(size_t size, SpaceType space_type, AllocatorType allocator_type, void *allocator_addr); 33 34 static void FreePoolImpl(void *mem, size_t size); 35 36 static AllocatorInfo GetAllocatorInfoForAddrImpl(void *addr); 37 38 static SpaceType GetSpaceTypeForAddrImpl(void *addr); 39 40 static void *GetStartAddrPoolForAddrImpl(void *addr); 41 42 MallocMemPool(); 43 44 ~MallocMemPool() override = default; 45 46 NO_COPY_SEMANTIC(MallocMemPool); 47 NO_MOVE_SEMANTIC(MallocMemPool); 48 49 friend class PoolManager; 50 friend class MemPool<MallocMemPool>; 51 }; 52 53 } // namespace panda 54 55 #endif // PANDA_LIBPANDABASE_MEM_MALLOC_MEM_POOL_H_ 56