Chromium Code Reviews| 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. | |
|
jar (doing other things)
2015/11/14 02:58:37
I'm not yet clear how you "hook in," but how do yo
Simon Que
2015/11/17 00:28:48
It was originally included in this CL, but since i
| |
| 20 // | |
| 21 // This is a stateless class, but there is static data within the module that | |
| 22 // needs to be created and deleted. | |
| 23 class CustomAllocator { | |
| 24 public: | |
| 25 using AllocFunc = std::add_pointer<void*(size_t)>::type; | |
| 26 using FreeFunc = std::add_pointer<void(void*, size_t)>::type; | |
| 27 | |
| 28 // Initialize CustomAllocator to use the default allocator. | |
| 29 static void Initialize(); | |
| 30 | |
| 31 // Initialize CustomAllocator to use the given alloc/free functions. | |
| 32 static void Initialize(AllocFunc alloc_func, FreeFunc free_func); | |
| 33 | |
| 34 // Performs any cleanup required, e.g. unset custom functions. Returns true | |
| 35 // on success or false if something failed. | |
| 36 static bool Shutdown(); | |
| 37 | |
| 38 static bool IsInitialized(); | |
| 39 | |
| 40 // These functions must match the specifications in STLAllocator. | |
| 41 static void* Allocate(size_t size); | |
| 42 static void Free(void* ptr, size_t size); | |
| 43 }; | |
| 44 | |
| 45 } // namespace leak_detector | |
| 46 } // namespace metrics | |
| 47 | |
| 48 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_CUSTOM_ALLOCATOR_H_ | |
| OLD | NEW |