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 definition.
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_JERRY_HEAP,  /* jerry independent heap memory pool */
60     MEM_TYPE_HICHAIN,      /* security memory pool */
61     MEM_TYPE_SOFTBUS_LSRAM,  /* softbus low speed memory pool */
62     MEM_TYPE_I18N_LSRAM = 111, /* global i18n low speed memory pool */
63     MEM_TYPE_CJSON_LSRAM = 114,
64     MEM_TYPE_APP_VERIFY_LSRAM = 116,
65 
66     MEM_TYPE_MAX           /* maximum definition of memory, add a new memory pool before it */
67 } MemType;
68 
69 /**
70  * @brief According to the input parameters type and size,
71  * memory is applied in the corresponding memory pool.
72  *
73  * Because memory management needs to consume memory,
74  * it is not recommended to use the memory application interface to apply for memory
75  * if the application memory is small (less than 8 bytes).
76  * Applying for small memory blocks is easy to cause memory fragmentation.
77  *
78  * @param type identify which memory pool to apply for memory in
79  * @param size size of memory block to apply for
80  * @return requested memory block address
81  * return if the memory request fails <b>NULL</b>.
82  * @since 1.0.
83  * @version 1.0.
84  */
85 void *OhosMalloc(MemType type, uint32 size);
86 
87 /**
88  * @brief free incoming memory space.
89  *
90  * @param ptr identify the memory blocks that need to be released.
91  * @attention Do not release null pointers or memory blocks not requested by OhosMalloc!
92  * @return void
93  * @since 1.0.
94  * @version 1.0.
95  */
96 void OhosFree(void *ptr);
97 
98 #ifdef __cplusplus
99 #if __cplusplus
100 }
101 #endif
102 #endif /* End of #ifdef __cplusplus */
103 
104 #endif /* End of #ifndef OHOS_MEM_POOL_H */
105 /** @} */