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

Unified 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: Unit tests. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: base/allocator/win_allocator.cc
diff --git a/base/allocator/win_allocator.cc b/base/allocator/win_allocator.cc
index 8ae653a690ed033b5e708e7021f98998082f0ca1..50b83e9a4dfd277bf42aa3a7989f7f343ba2048e 100644
--- a/base/allocator/win_allocator.cc
+++ b/base/allocator/win_allocator.cc
@@ -47,4 +47,21 @@ size_t win_heap_msize(void* ptr) {
return HeapSize(win_heap, 0, ptr);
}
+void* win_heap_memalign(size_t alignment, size_t size) {
+ // Reserve enough space to ensure we can align and set aligned_ptr[-1] to the
jar (doing other things) 2012/07/30 23:04:22 I think you may want to be cautious about args her
DaleCurtis 2012/07/31 00:44:22 Can you elaborate on the trouble we could face? Fr
jar (doing other things) 2012/07/31 03:18:51 I didn't see where the args were being validated.
DaleCurtis 2012/07/31 03:39:48 Gotcha, I thought there might be some weird HeapAl
+ // original allocation for use with win_heap_memalign_free() later.
+ void* ptr = win_heap_malloc(size + (alignment - 1) + sizeof(void*));
+
+ char* aligned_ptr = static_cast<char*>(ptr) + sizeof(void*);
+ aligned_ptr +=
+ alignment - reinterpret_cast<uintptr_t>(aligned_ptr) & (alignment - 1);
+
+ reinterpret_cast<void**>(aligned_ptr)[-1] = ptr;
+ return aligned_ptr;
+}
+
+void win_heap_memalign_free(void* ptr) {
+ win_heap_free(static_cast<void**>(ptr)[-1]);
+}
+
} // extern "C"

Powered by Google App Engine
This is Rietveld 408576698