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

Unified Diff: base/allocator/allocator_shim.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
« no previous file with comments | « no previous file | base/allocator/allocator_unittests.cc » ('j') | base/allocator/allocator_unittests.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/allocator_shim.cc
diff --git a/base/allocator/allocator_shim.cc b/base/allocator/allocator_shim.cc
index fd6d741c04d3e195c00305477fbf9a26553e38dc..a16c106ec893589c00e8c7587575cc32b0ccc712 100644
--- a/base/allocator/allocator_shim.cc
+++ b/base/allocator/allocator_shim.cc
@@ -65,6 +65,7 @@ void* je_realloc(void* p, size_t s);
void je_free(void* s);
size_t je_msize(void* p);
bool je_malloc_init_hard();
+void* je_memalign(size_t a, size_t s);
}
extern "C" {
@@ -299,6 +300,53 @@ extern "C" void _heap_term() {}
// the rest of the CRT is still usable.
extern "C" void* _crtheap = reinterpret_cast<void*>(1);
+// Provide support for aligned memory through Windows only _aligned_malloc().
+void* _aligned_malloc(size_t size, size_t alignment) {
+ void* ptr;
+ for (;;) {
+#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
+ switch (allocator) {
+ case JEMALLOC:
+ ptr = je_memalign(alignment, size);
+ break;
+ case WINHEAP:
+ case WINLFH:
+ ptr = win_heap_memalign(alignment, size);
+ break;
+ case TCMALLOC:
+ default:
+ ptr = tc_memalign(alignment, size);
+ break;
+ }
+#else
+ // TCMalloc case.
+ ptr = tc_memalign(alignment, size);
+#endif
+ if (ptr)
+ return ptr;
+
+ if (!new_mode || !call_new_handler(true))
+ break;
+ }
+ return ptr;
+}
+
+void _aligned_free(void* p) {
+#ifdef ENABLE_DYNAMIC_ALLOCATOR_SWITCHING
+ switch (allocator) {
+ case JEMALLOC:
+ je_free(p);
+ return;
+ case WINHEAP:
+ case WINLFH:
+ win_heap_memalign_free(p);
+ return;
+ }
+#endif
+ // TCMalloc case.
+ do_free(p);
+}
+
#endif // WIN32
#include "generic_allocators.cc"
« no previous file with comments | « no previous file | base/allocator/allocator_unittests.cc » ('j') | base/allocator/allocator_unittests.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698