| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_METRICS_LEAK_DETECTOR_CUSTOM_ALLOCATOR_H_ | |
| 6 #define COMPONENTS_METRICS_LEAK_DETECTOR_CUSTOM_ALLOCATOR_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <type_traits> | |
| 11 | |
| 12 namespace metrics { | |
| 13 namespace leak_detector { | |
| 14 | |
| 15 // Custom allocator class to be passed to STLAllocator as a template argument. | |
| 16 // | |
| 17 // By default, CustomAllocator uses the default allocator (new/delete), but the | |
| 18 // caller of Initialize ()can provide a pair of alternative alloc/ free | |
| 19 // functions to use as an external allocator. | |
| 20 // | |
| 21 // This is a stateless class, but there is static data within the module that | |
| 22 // needs to be created and deleted. | |
| 23 // | |
| 24 // Not thread-safe. | |
| 25 class CustomAllocator { | |
| 26 public: | |
| 27 using AllocFunc = std::add_pointer<void*(size_t)>::type; | |
| 28 using FreeFunc = std::add_pointer<void(void*, size_t)>::type; | |
| 29 | |
| 30 // Initialize CustomAllocator to use the default allocator. | |
| 31 static void Initialize(); | |
| 32 | |
| 33 // Initialize CustomAllocator to use the given alloc/free functions. | |
| 34 static void Initialize(AllocFunc alloc_func, FreeFunc free_func); | |
| 35 | |
| 36 // Performs any cleanup required, e.g. unset custom functions. Returns true | |
| 37 // on success or false if something failed. | |
| 38 static bool Shutdown(); | |
| 39 | |
| 40 static bool IsInitialized(); | |
| 41 | |
| 42 // These functions must match the specifications in STLAllocator. | |
| 43 static void* Allocate(size_t size); | |
| 44 static void Free(void* ptr, size_t size); | |
| 45 }; | |
| 46 | |
| 47 } // namespace leak_detector | |
| 48 } // namespace metrics | |
| 49 | |
| 50 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_CUSTOM_ALLOCATOR_H_ | |
| OLD | NEW |