ncnn
1// Leo is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2018 Leo <leo@nullptr.com.cn>. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#include "platform.h"16
17#if NCNN_SIMPLESTL18
19#include <stdlib.h>20
21// allocation functions
22void* operator new(size_t size)23{
24return malloc(size);25}
26
27void* operator new[](size_t size)28{
29return malloc(size);30}
31
32// placement allocation functions
33void* operator new(size_t /*size*/, void* ptr)34{
35return ptr;36}
37
38void* operator new[](size_t /*size*/, void* ptr)39{
40return ptr;41}
42
43// deallocation functions
44void operator delete(void* ptr)45{
46free(ptr);47}
48
49void operator delete[](void* ptr)50{
51free(ptr);52}
53
54// deallocation functions since c++14
55#if __cplusplus >= 201402L56
57void operator delete(void* ptr, size_t sz)58{
59free(ptr);60}
61
62void operator delete[](void* ptr, size_t sz)63{
64free(ptr);65}
66
67#endif68
69// placement deallocation functions
70void operator delete(void* /*ptr*/, void* /*voidptr2*/)71{
72}
73
74void operator delete[](void* /*ptr*/, void* /*voidptr2*/)75{
76}
77
78extern "C" void __cxa_pure_virtual()79{
80NCNN_LOGE("[Fatal] Pure virtual func called, now exit.");81// do not abort here to avoid more unpredictable behaviour82}
83
84#endif // NCNN_SIMPLESTL85