Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: components/metrics/leak_detector/custom_allocator.h

Issue 986503002: components/metrics: Add runtime memory leak detector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac build fixes: const arg in comparator, rm const in func return type Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_
OLDNEW
« no previous file with comments | « components/metrics/leak_detector/call_stack_table_unittest.cc ('k') | components/metrics/leak_detector/custom_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698