diff options
author | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-25 03:21:47 +0000 |
---|---|---|
committer | sgk@chromium.org <sgk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-25 03:21:47 +0000 |
commit | 6a7e698052d3b0d0aafebd5ac6af0ef2f95ff2a9 (patch) | |
tree | 92133e44fa5b002e390da3b90c2aa7b1477c0a87 /base/allocator/win_allocator.cc | |
parent | 8fa0b967bf38ffec49daf8cceed81603ed4316a7 (diff) | |
download | chromium_src-6a7e698052d3b0d0aafebd5ac6af0ef2f95ff2a9.zip chromium_src-6a7e698052d3b0d0aafebd5ac6af0ef2f95ff2a9.tar.gz chromium_src-6a7e698052d3b0d0aafebd5ac6af0ef2f95ff2a9.tar.bz2 |
Branch the files in the shim layer that switches between the
memory allocation implementations (tcmalloc, jemalloc, etc.) into a
base\allocator library.
BUG=27911
TEST=none
Review URL: http://codereview.chromium.org/434067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33043 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/allocator/win_allocator.cc')
-rw-r--r-- | base/allocator/win_allocator.cc | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/base/allocator/win_allocator.cc b/base/allocator/win_allocator.cc new file mode 100644 index 0000000..8ae653a --- /dev/null +++ b/base/allocator/win_allocator.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This is a simple allocator based on the windows heap. + +extern "C" { + +HANDLE win_heap; + +bool win_heap_init(bool use_lfh) { + win_heap = HeapCreate(0, 0, 0); + if (win_heap == NULL) + return false; + + if (use_lfh) { + ULONG enable_lfh = 2; + HeapSetInformation(win_heap, HeapCompatibilityInformation, + &enable_lfh, sizeof(enable_lfh)); + // NOTE: Setting LFH may fail. Vista already has it enabled. + // And under the debugger, it won't use LFH. So we + // ignore any errors. + } + + return true; +} + +void* win_heap_malloc(size_t size) { + return HeapAlloc(win_heap, 0, size); +} + +void win_heap_free(void* size) { + HeapFree(win_heap, 0, size); +} + +void* win_heap_realloc(void* ptr, size_t size) { + if (!ptr) + return win_heap_malloc(size); + if (!size) { + win_heap_free(ptr); + return NULL; + } + return HeapReAlloc(win_heap, 0, ptr, size); +} + +size_t win_heap_msize(void* ptr) { + return HeapSize(win_heap, 0, ptr); +} + +} // extern "C" |