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

Side by Side Diff: base/allocator/win_allocator.cc

Issue 10828054: Modify allocator_shim to support _aligned_alloc(), _aligned_free(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Land jemalloc.c change separately. Created 8 years, 4 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
« no previous file with comments | « base/allocator/allocator_unittests.cc ('k') | third_party/jemalloc/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 29 matching lines...) Expand all
40 win_heap_free(ptr); 40 win_heap_free(ptr);
41 return NULL; 41 return NULL;
42 } 42 }
43 return HeapReAlloc(win_heap, 0, ptr, size); 43 return HeapReAlloc(win_heap, 0, ptr, size);
44 } 44 }
45 45
46 size_t win_heap_msize(void* ptr) { 46 size_t win_heap_msize(void* ptr) {
47 return HeapSize(win_heap, 0, ptr); 47 return HeapSize(win_heap, 0, ptr);
48 } 48 }
49 49
50 void* win_heap_memalign(size_t alignment, size_t size) {
51 // Reserve enough space to ensure we can align and set aligned_ptr[-1] to the
52 // original allocation for use with win_heap_memalign_free() later.
53 size_t allocation_size = size + (alignment - 1) + sizeof(void*);
54
55 // Check for overflow. Alignment and size are checked in allocator_shim.
56 DCHECK_LT(size, allocation_size);
57 DCHECK_LT(alignment, allocation_size);
58
59 void* ptr = win_heap_malloc(allocation_size);
60 char* aligned_ptr = static_cast<char*>(ptr) + sizeof(void*);
61 aligned_ptr +=
62 alignment - reinterpret_cast<uintptr_t>(aligned_ptr) & (alignment - 1);
63
64 reinterpret_cast<void**>(aligned_ptr)[-1] = ptr;
65 return aligned_ptr;
66 }
67
68 void win_heap_memalign_free(void* ptr) {
69 win_heap_free(static_cast<void**>(ptr)[-1]);
70 }
71
50 } // extern "C" 72 } // extern "C"
OLDNEW
« no previous file with comments | « base/allocator/allocator_unittests.cc ('k') | third_party/jemalloc/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698