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

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: Replace tcmalloc's wrappers with pthread_spinlock and standard allocator (no more tcmalloc changes) Created 5 years, 2 months 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 leak_detector {
13
14 // Custom allocator class to be passed to STL_Allocator as a template argument.
15 //
16 // By default, CustomAllocator uses the default allocator (new/delete), but the
17 // caller of Initialize ()can provide a pair of alternative alloc/ free
18 // functions to use as an external allocator.
19 //
20 // This is a stateless class, but there is static data within the module that
21 // needs to be created and deleted.
22 class CustomAllocator {
23 public:
24 using AllocFunc = std::add_pointer<void*(size_t)>::type;
25 using FreeFunc = std::add_pointer<void(void*, size_t)>::type;
26
27 // Initialize CustomAllocator to use the default allocator.
28 static void Initialize();
29
30 // Initialize CustomAllocator to use the given alloc/free functions.
31 static void Initialize(AllocFunc alloc_func, FreeFunc free_func);
32
33 // Performs any cleanup required, e.g. unset custom functions. Returns true
34 // on success or false if something failed.
35 static bool Shutdown();
36
37 static bool IsInitialized();
38
39 // These functions must match the specifications in STL_Allocator.
40 static void* Allocate(size_t size);
41 static void Free(void* ptr, size_t size);
42 };
43
44 } // namespace
45
46 #endif // COMPONENTS_METRICS_LEAK_DETECTOR_CUSTOM_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698