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 /** 17 * @addtogroup ohos_mem_pool 18 * @{ 19 * 20 * @brief Provides functions for memory alloc and memory free. 21 * 22 * @since 1.0 23 * @version 1.0 24 */ 25 26 /** 27 * @file ohos_mem_pool.h 28 * 29 * @brief Provides functions for memory alloc and memory free. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 35 #ifndef OHOS_MEM_POOL_H 36 #define OHOS_MEM_POOL_H 37 38 #include "ohos_types.h" 39 40 #ifdef __cplusplus 41 #if __cplusplus 42 extern "C"{ 43 #endif 44 #endif /* End of #ifdef __cplusplus */ 45 46 /** 47 * @brief memory pool enum defination. 48 */ 49 typedef enum { 50 MEM_TYPE_BEGIN = 100, 51 MEM_TYPE_UIKIT = MEM_TYPE_BEGIN, /* UIKIT memory pool */ 52 MEM_TYPE_UIKIT_LSRAM, /* UIKIT low speed memory pool */ 53 MEM_TYPE_APPFMK, /* appexecfmk memory pool */ 54 MEM_TYPE_APPFMK_LSRAM, /* appexecfmk low speed memory pool */ 55 MEM_TYPE_ACE, /* ACE memory pool */ 56 MEM_TYPE_ACE_LSRAM, /* ACE low speed memory pool */ 57 MEM_TYPE_JERRY, /* jerry script memory pool */ 58 MEM_TYPE_JERRY_LSRAM, /* jerry script low speed memory pool */ 59 MEM_TYPE_HICHAIN, /* security memory pool */ 60 MEM_TYPE_SOFTBUS_LSRAM, /* softbus low speed memory pool */ 61 62 MEM_TYPE_MAX /* maximum defination of memory ,add a new memory pool before it */ 63 } MemType; 64 65 /** 66 * @brief According to the input parameters type and size, 67 * memory is applied in the corresponding memory pool. 68 * 69 * Because memory management needs to consume memory, 70 * it is not recommended to use the memory application interface to apply for memory 71 * if the application memory is small (less than 8 bytes). 72 * Applying for small memory blocks is easy to cause memory fragmentation. 73 * 74 * @param type identify which memory pool to apply for memory in 75 * @param size size of memory block to apply for 76 * @return requested memory block address 77 * return if the memory request fails <b>NULL</b>. 78 * @since 1.0. 79 * @version 1.0. 80 */ 81 void *OhosMalloc(MemType type, uint32 size); 82 83 /** 84 * @brief free incoming memory space. 85 * 86 * @param ptr identify the memory blocks that need to be released. 87 * @attention Do not release null pointers or memory blocks not requested by OhosMalloc! 88 * @return void 89 * @since 1.0. 90 * @version 1.0. 91 */ 92 void OhosFree(void *ptr); 93 94 #ifdef __cplusplus 95 #if __cplusplus 96 } 97 #endif 98 #endif /* End of #ifdef __cplusplus */ 99 100 #endif /* End of #ifndef OHOS_MEM_POOL_H */ 101 /** @} */