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

Unified Diff: base/stack_container.h

Issue 9186057: Add ALIGNAS and ALIGNOF macros to ensure proper alignment of StaticMemorySingletonTraits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: willchan feedback Created 8 years, 10 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 | « base/memory/singleton_unittest.cc ('k') | base/stack_container_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/stack_container.h
diff --git a/base/stack_container.h b/base/stack_container.h
index dc946db6751f8503f07c6e0fd84edfcb1edf857b..06ef2a4f576804231d0bb5b597c3ec9482069063 100644
--- a/base/stack_container.h
+++ b/base/stack_container.h
@@ -10,6 +10,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/memory/aligned_memory.h"
// This allocator can be used with STL containers to provide a stack buffer
// from which to allocate memory and overflows onto the heap. This stack buffer
@@ -43,22 +44,15 @@ class StackAllocator : public std::allocator<T> {
}
// Casts the buffer in its right type.
- T* stack_buffer() { return reinterpret_cast<T*>(stack_buffer_); }
+ T* stack_buffer() { return stack_buffer_.template data_as<T>(); }
const T* stack_buffer() const {
- return reinterpret_cast<const T*>(stack_buffer_);
+ return stack_buffer_.template data_as<T>();
}
- //
- // IMPORTANT: Take care to ensure that stack_buffer_ is aligned
- // since it is used to mimic an array of T.
- // Be careful while declaring any unaligned types (like bool)
- // before stack_buffer_.
- //
-
// The buffer itself. It is not of type T because we don't want the
// constructors and destructors to be automatically called. Define a POD
// buffer of the right size instead.
- char stack_buffer_[sizeof(T[stack_capacity])];
+ base::AlignedMemory<sizeof(T[stack_capacity]), ALIGNOF(T)> stack_buffer_;
// Set when the stack buffer is used for an allocation. We do not track
// how much of the buffer is used, only that somebody is using it.
« no previous file with comments | « base/memory/singleton_unittest.cc ('k') | base/stack_container_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698