| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is a simple allocator based on the windows heap. | 5 // This is a simple allocator based on the windows heap. |
| 6 | 6 |
| 7 extern "C" { | 7 extern "C" { |
| 8 | 8 |
| 9 HANDLE win_heap; | 9 HANDLE win_heap; |
| 10 | 10 |
| 11 bool win_heap_init(bool use_lfh) { | 11 bool win_heap_init(bool use_lfh) { |
| 12 win_heap = HeapCreate(0, 0, 0); | 12 win_heap = HeapCreate(0, 0, 0); |
| 13 if (win_heap == NULL) | 13 if (win_heap == NULL) |
| 14 return false; | 14 return false; |
| 15 | 15 |
| 16 if (use_lfh) { | 16 if (use_lfh) { |
| 17 ULONG enable_lfh = 2; | 17 ULONG enable_lfh = 2; |
| 18 HeapSetInformation(win_heap, HeapCompatibilityInformation, | 18 HeapSetInformation(win_heap, HeapCompatibilityInformation, |
| 19 &enable_lfh, sizeof(enable_lfh)); | 19 &enable_lfh, sizeof(enable_lfh)); |
| 20 // NOTE: Setting LFH may fail. Vista already has it enabled. | 20 // NOTE: Setting LFH may fail. Vista already has it enabled. |
| 21 // And under the debugger, it won't use LFH. So we | 21 // And under the debugger, it won't use LFH. So we |
| 22 // ignore any errors. | 22 // ignore any errors. |
| 23 } | 23 } |
| 24 | 24 |
| 25 return true; | 25 return true; |
| 26 } | 26 } |
| 27 | 27 |
| 28 void* win_heap_malloc(size_t s) { | 28 void* win_heap_malloc(size_t size) { |
| 29 return HeapAlloc(win_heap, 0, s); | 29 return HeapAlloc(win_heap, 0, size); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void* win_heap_realloc(void* p, size_t s) { | 32 void win_heap_free(void* size) { |
| 33 if (!p) | 33 HeapFree(win_heap, 0, size); |
| 34 return win_heap_malloc(s); | |
| 35 return HeapReAlloc(win_heap, 0, p, s); | |
| 36 } | 34 } |
| 37 | 35 |
| 38 void win_heap_free(void* s) { | 36 void* win_heap_realloc(void* ptr, size_t size) { |
| 39 HeapFree(win_heap, 0, s); | 37 if (!ptr) |
| 38 return win_heap_malloc(size); |
| 39 if (!size) { |
| 40 win_heap_free(ptr); |
| 41 return NULL; |
| 42 } |
| 43 return HeapReAlloc(win_heap, 0, ptr, size); |
| 40 } | 44 } |
| 41 | 45 |
| 42 size_t win_heap_msize(void* p) { | 46 size_t win_heap_msize(void* ptr) { |
| 43 return HeapSize(win_heap, 0, p); | 47 return HeapSize(win_heap, 0, ptr); |
| 44 } | 48 } |
| 45 | 49 |
| 46 } // extern "C" | 50 } // extern "C" |
| OLD | NEW |