1 /* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef CONNECTION_CONTROL_MEMORY_H
24 #define CONNECTION_CONTROL_MEMORY_H
25 
26 #include <my_global.h>
27 #include <my_sys.h>
28 #include <limits>
29 #include <memory>
30 
31 namespace connection_control
32 {
33   template <class T>
Connection_control_malloc(size_t size)34   T Connection_control_malloc(size_t size)
35   {
36     void *allocated_memory= my_malloc(size, MYF(MY_WME));
37     return allocated_memory ? reinterpret_cast<T>(allocated_memory) : NULL;
38   }
39 
40   class Connection_control_alloc
41   {
42     public:
new(size_t size)43       static void *operator new(size_t size) throw ()
44       {
45         return Connection_control_malloc<void*>(size);
46       }
throw()47       static void *operator new[](size_t size) throw ()
48       {
49         return Connection_control_malloc<void*>(size);
50       }
delete(void * ptr,std::size_t sz)51       static void operator delete(void* ptr, std::size_t sz)
52       {
53           my_free(ptr);
54       }
55       static void operator delete[](void* ptr, std::size_t sz)
56       {
57           my_free(ptr);
58       }
59   };
60 }
61 
62 #endif //CONNECTION_CONTROL_MEMORY_H
63