1 /*
2  * Copyright (c) 2020-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 UI_Utils
18  * @{
19  *
20  * @brief Defines basic UI utils.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file heap_base.h
28  *
29  * @brief Declares the functions for overriding the <b>new</b> and <b>delete</b> functions.
30  *
31  * @since 1.0
32  * @version 1.0
33  */
34 
35 #ifndef GRAPHIC_LITE_HEAP_BASE_H
36 #define GRAPHIC_LITE_HEAP_BASE_H
37 
38 #include "graphic_config.h"
39 #include "gfx_utils/mem_api.h"
40 #include <stddef.h>
41 namespace OHOS {
42 /**
43  * @brief Defines the base class, overriding the <b>new</b> and <b>delete</b> functions.
44  *
45  * @since 1.0
46  * @version 1.0
47  */
48 class HeapBase {
49 public:
50 #if ENABLE_MEMORY_HOOKS
51     /**
52      * @brief Overrides the <b>new</b> function.
53      * @param size Indicates the size of the memory to be allocated.
54      *
55      * @since 1.0
56      * @version 1.0
57      */
new(size_t size)58     void* operator new(size_t size)
59     {
60         return UIMalloc(static_cast<uint32_t>(size));
61     }
62 
63     /**
64      * @brief Overrides the <b>delete</b> function.
65      * @param p Indicates the pointer to the memory to be released.
66      *
67      * @since 1.0
68      * @version 1.0
69      */
delete(void * p)70     void operator delete(void* p)
71     {
72         UIFree(p);
73     }
74 #endif
75 };
76 } // namespace OHOS
77 #endif //
78