README
1Notes about the Chrome memory allocator.
2
3Background
4----------
5We use this library as a generic way to fork into any of several allocators.
6Currently we can, at runtime, switch between:
7 the default windows allocator
8 the windows low-fragmentation-heap
9 tcmalloc
10
11The mechanism for hooking LIBCMT in windows is rather tricky. The core
12problem is that by default, the windows library does not declare malloc and
13free as weak symbols. Because of this, they cannot be overriden. To work
14around this, we start with the LIBCMT.LIB, and manually remove all allocator
15related functions from it using the visual studio library tool. Once removed,
16we can now link against the library and provide custom versions of the
17allocator related functionality.
18
19
20Source code
21-----------
22This directory contains just the allocator (i.e. shim) layer that switches
23between the different underlying memory allocation implementations.
24
25The tcmalloc library originates outside of Chromium and exists in
26../../third_party/tcmalloc (currently, the actual location is defined in the
27allocator.gyp file). The third party sources use a vendor-branch SCM pattern to
28track Chromium-specific changes independently from upstream changes.
29
30The general intent is to push local changes upstream so that over
31time we no longer need any forked files.
32
33
34Adding a new allocator
35----------------------
36Adding a new allocator requires definition of the following five functions:
37
38 extern "C" {
39 bool init();
40 void* malloc(size_t s);
41 void* realloc(void* p, size_t s);
42 void free(void* s);
43 size_t msize(void* p);
44 }
45
46All other allocation related functions (new/delete/calloc/etc) have been
47implemented generically to work across all allocators.
48
49
50Usage
51-----
52You can use the different allocators by setting the environment variable
53CHROME_ALLOCATOR to:
54 "tcmalloc" - TC Malloc (default)
55 "winheap" - Windows default heap
56 "winlfh" - Windows Low-Fragmentation heap
57