10e98b08fSopenharmony_ci/*
20e98b08fSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
30e98b08fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40e98b08fSopenharmony_ci * you may not use this file except in compliance with the License.
50e98b08fSopenharmony_ci * You may obtain a copy of the License at
60e98b08fSopenharmony_ci *
70e98b08fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80e98b08fSopenharmony_ci *
90e98b08fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100e98b08fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110e98b08fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120e98b08fSopenharmony_ci * See the License for the specific language governing permissions and
130e98b08fSopenharmony_ci * limitations under the License.
140e98b08fSopenharmony_ci */
150e98b08fSopenharmony_ci
160e98b08fSopenharmony_ci/**
170e98b08fSopenharmony_ci * @addtogroup ohos_mem_pool
180e98b08fSopenharmony_ci * @{
190e98b08fSopenharmony_ci *
200e98b08fSopenharmony_ci * @brief Provides functions for memory alloc and memory free.
210e98b08fSopenharmony_ci *
220e98b08fSopenharmony_ci * @since 1.0
230e98b08fSopenharmony_ci * @version 1.0
240e98b08fSopenharmony_ci */
250e98b08fSopenharmony_ci
260e98b08fSopenharmony_ci/**
270e98b08fSopenharmony_ci * @file ohos_mem_pool.h
280e98b08fSopenharmony_ci *
290e98b08fSopenharmony_ci * @brief Provides functions for memory alloc and memory free.
300e98b08fSopenharmony_ci *
310e98b08fSopenharmony_ci * @since 1.0
320e98b08fSopenharmony_ci * @version 1.0
330e98b08fSopenharmony_ci */
340e98b08fSopenharmony_ci
350e98b08fSopenharmony_ci#ifndef OHOS_MEM_POOL_H
360e98b08fSopenharmony_ci#define OHOS_MEM_POOL_H
370e98b08fSopenharmony_ci
380e98b08fSopenharmony_ci#include "ohos_types.h"
390e98b08fSopenharmony_ci
400e98b08fSopenharmony_ci#ifdef __cplusplus
410e98b08fSopenharmony_ci#if __cplusplus
420e98b08fSopenharmony_ciextern "C"{
430e98b08fSopenharmony_ci#endif
440e98b08fSopenharmony_ci#endif /* End of #ifdef __cplusplus */
450e98b08fSopenharmony_ci
460e98b08fSopenharmony_ci/**
470e98b08fSopenharmony_ci * @brief memory pool enum definition.
480e98b08fSopenharmony_ci */
490e98b08fSopenharmony_citypedef enum {
500e98b08fSopenharmony_ci    MEM_TYPE_BEGIN = 100,
510e98b08fSopenharmony_ci    MEM_TYPE_UIKIT = MEM_TYPE_BEGIN, /* UIKIT memory pool */
520e98b08fSopenharmony_ci    MEM_TYPE_UIKIT_LSRAM,  /* UIKIT low speed memory pool */
530e98b08fSopenharmony_ci    MEM_TYPE_APPFMK,       /* appexecfmk memory pool */
540e98b08fSopenharmony_ci    MEM_TYPE_APPFMK_LSRAM, /* appexecfmk low speed memory pool */
550e98b08fSopenharmony_ci    MEM_TYPE_ACE,          /* ACE memory pool */
560e98b08fSopenharmony_ci    MEM_TYPE_ACE_LSRAM,    /* ACE low speed memory pool */
570e98b08fSopenharmony_ci    MEM_TYPE_JERRY,        /* jerry script memory pool */
580e98b08fSopenharmony_ci    MEM_TYPE_JERRY_LSRAM,  /* jerry script low speed memory pool */
590e98b08fSopenharmony_ci    MEM_TYPE_JERRY_HEAP,  /* jerry independent heap memory pool */
600e98b08fSopenharmony_ci    MEM_TYPE_HICHAIN,      /* security memory pool */
610e98b08fSopenharmony_ci    MEM_TYPE_SOFTBUS_LSRAM,  /* softbus low speed memory pool */
620e98b08fSopenharmony_ci    MEM_TYPE_I18N_LSRAM = 111, /* global i18n low speed memory pool */
630e98b08fSopenharmony_ci    MEM_TYPE_CJSON_LSRAM = 114,
640e98b08fSopenharmony_ci    MEM_TYPE_APP_VERIFY_LSRAM = 116,
650e98b08fSopenharmony_ci
660e98b08fSopenharmony_ci    MEM_TYPE_MAX           /* maximum definition of memory, add a new memory pool before it */
670e98b08fSopenharmony_ci} MemType;
680e98b08fSopenharmony_ci
690e98b08fSopenharmony_ci/**
700e98b08fSopenharmony_ci * @brief According to the input parameters type and size,
710e98b08fSopenharmony_ci * memory is applied in the corresponding memory pool.
720e98b08fSopenharmony_ci *
730e98b08fSopenharmony_ci * Because memory management needs to consume memory,
740e98b08fSopenharmony_ci * it is not recommended to use the memory application interface to apply for memory
750e98b08fSopenharmony_ci * if the application memory is small (less than 8 bytes).
760e98b08fSopenharmony_ci * Applying for small memory blocks is easy to cause memory fragmentation.
770e98b08fSopenharmony_ci *
780e98b08fSopenharmony_ci * @param type identify which memory pool to apply for memory in
790e98b08fSopenharmony_ci * @param size size of memory block to apply for
800e98b08fSopenharmony_ci * @return requested memory block address
810e98b08fSopenharmony_ci * return if the memory request fails <b>NULL</b>.
820e98b08fSopenharmony_ci * @since 1.0.
830e98b08fSopenharmony_ci * @version 1.0.
840e98b08fSopenharmony_ci */
850e98b08fSopenharmony_civoid *OhosMalloc(MemType type, uint32 size);
860e98b08fSopenharmony_ci
870e98b08fSopenharmony_ci/**
880e98b08fSopenharmony_ci * @brief free incoming memory space.
890e98b08fSopenharmony_ci *
900e98b08fSopenharmony_ci * @param ptr identify the memory blocks that need to be released.
910e98b08fSopenharmony_ci * @attention Do not release null pointers or memory blocks not requested by OhosMalloc!
920e98b08fSopenharmony_ci * @return void
930e98b08fSopenharmony_ci * @since 1.0.
940e98b08fSopenharmony_ci * @version 1.0.
950e98b08fSopenharmony_ci */
960e98b08fSopenharmony_civoid OhosFree(void *ptr);
970e98b08fSopenharmony_ci
980e98b08fSopenharmony_ci#ifdef __cplusplus
990e98b08fSopenharmony_ci#if __cplusplus
1000e98b08fSopenharmony_ci}
1010e98b08fSopenharmony_ci#endif
1020e98b08fSopenharmony_ci#endif /* End of #ifdef __cplusplus */
1030e98b08fSopenharmony_ci
1040e98b08fSopenharmony_ci#endif /* End of #ifndef OHOS_MEM_POOL_H */
1050e98b08fSopenharmony_ci/** @} */