summaryrefslogtreecommitdiffstats
path: root/base/stack_container.h
diff options
context:
space:
mode:
authorjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-23 17:52:20 +0000
committerjbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-23 17:52:20 +0000
commitcd924d6e5efdf80f66283ac66987f2b339c381cf (patch)
tree89d2ccd8588e12669b93eb98117e8d76a766fbf2 /base/stack_container.h
parent2e8bb832c7b3867b3a10b81621830add0dd5bfb5 (diff)
downloadchromium_src-cd924d6e5efdf80f66283ac66987f2b339c381cf.zip
chromium_src-cd924d6e5efdf80f66283ac66987f2b339c381cf.tar.gz
chromium_src-cd924d6e5efdf80f66283ac66987f2b339c381cf.tar.bz2
Add ALIGNAS and ALIGNOF macros to ensure proper alignment of StaticMemorySingletonTraits
BUG=95006 Review URL: https://chromiumcodereview.appspot.com/9186057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/stack_container.h')
-rw-r--r--base/stack_container.h14
1 files changed, 4 insertions, 10 deletions
diff --git a/base/stack_container.h b/base/stack_container.h
index dc946db..06ef2a4 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.