1 | #ifndef SQL_ALLOC_INCLUDED |
2 | #define SQL_ALLOC_INCLUDED |
3 | /* Copyright (c) 2000, 2012, Oracle and/or its affiliates. |
4 | Copyright (c) 2017, 2018, MariaDB Corporation. |
5 | |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; version 2 of the License. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
18 | |
19 | #include <my_sys.h> /* alloc_root, MEM_ROOT, TRASH */ |
20 | |
21 | THD *thd_get_current_thd(); |
22 | |
23 | /* mysql standard class memory allocator */ |
24 | |
25 | class Sql_alloc |
26 | { |
27 | public: |
28 | static void *operator new(size_t size) throw () |
29 | { |
30 | return thd_alloc(thd_get_current_thd(), size); |
31 | } |
32 | static void *operator new[](size_t size) throw () |
33 | { |
34 | return thd_alloc(thd_get_current_thd(), size); |
35 | } |
36 | static void *operator new[](size_t size, MEM_ROOT *mem_root) throw () |
37 | { return alloc_root(mem_root, size); } |
38 | static void *operator new(size_t size, MEM_ROOT *mem_root) throw() |
39 | { return alloc_root(mem_root, size); } |
40 | static void operator delete(void *ptr, size_t size) { TRASH_FREE(ptr, size); } |
41 | static void operator delete(void *, MEM_ROOT *){} |
42 | static void operator delete[](void *, MEM_ROOT *) |
43 | { /* never called */ } |
44 | static void operator delete[](void *ptr, size_t size) { TRASH_FREE(ptr, size); } |
45 | #ifdef HAVE_valgrind |
46 | bool dummy_for_valgrind; |
47 | inline Sql_alloc() :dummy_for_valgrind(0) {} |
48 | #else |
49 | inline Sql_alloc() {} |
50 | #endif |
51 | inline ~Sql_alloc() {} |
52 | }; |
53 | #endif /* SQL_ALLOC_INCLUDED */ |
54 | |