OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // When possible, we implement allocator functions on top of the basic | 5 // When possible, we implement allocator functions on top of the basic |
6 // low-level functions malloc() and free(). This way, including a new | 6 // low-level functions malloc() and free(). This way, including a new |
7 // allocator is as simple as providing just a small interface. | 7 // allocator is as simple as providing just a small interface. |
8 // | 8 // |
9 // As such, this file should not contain any allocator-specific code. | 9 // As such, this file should not contain any allocator-specific code. |
10 | 10 |
11 // Implement a C++ style allocation, which always calls the new_handler | 11 // Implement a C++ style allocation, which always calls the new_handler |
12 // on failure. | 12 // on failure. |
13 inline void* generic_cpp_alloc(size_t size, bool nothrow) { | 13 inline void* generic_cpp_alloc(size_t size, bool nothrow) { |
14 void* ptr; | 14 void* ptr; |
15 for (;;) { | 15 for (;;) { |
16 ptr = malloc(size); | 16 ptr = malloc(size); |
17 if (ptr) | 17 if (ptr) |
18 return ptr; | 18 return ptr; |
19 if (!call_new_handler(nothrow)) | 19 if (!call_new_handler(nothrow, size)) |
20 break; | 20 break; |
21 } | 21 } |
22 return ptr; | 22 return ptr; |
23 } | 23 } |
24 | 24 |
25 extern "C++" { | 25 extern "C++" { |
26 | 26 |
27 void* operator new(size_t size) { | 27 void* operator new(size_t size) { |
28 return generic_cpp_alloc(size, false); | 28 return generic_cpp_alloc(size, false); |
29 } | 29 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 void* _calloc_dbg(size_t n, size_t size, int, const char*, int) { | 168 void* _calloc_dbg(size_t n, size_t size, int, const char*, int) { |
169 return calloc(n, size); | 169 return calloc(n, size); |
170 } | 170 } |
171 #endif // NDEBUG | 171 #endif // NDEBUG |
172 | 172 |
173 #endif // WIN32 | 173 #endif // WIN32 |
174 | 174 |
175 } // extern C | 175 } // extern C |
176 | 176 |
OLD | NEW |