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

Side by Side Diff: base/stack_container.h

Issue 10796020: Upgrade AlignedMemory to support dynamic allocations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Documentation. 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 unified diff | Download patch | Annotate | Revision Log
« base/memory/aligned_memory.h ('K') | « base/memory/singleton.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_STACK_CONTAINER_H_ 5 #ifndef BASE_STACK_CONTAINER_H_
6 #define BASE_STACK_CONTAINER_H_ 6 #define BASE_STACK_CONTAINER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 // Casts the buffer in its right type. 46 // Casts the buffer in its right type.
47 T* stack_buffer() { return stack_buffer_.template data_as<T>(); } 47 T* stack_buffer() { return stack_buffer_.template data_as<T>(); }
48 const T* stack_buffer() const { 48 const T* stack_buffer() const {
49 return stack_buffer_.template data_as<T>(); 49 return stack_buffer_.template data_as<T>();
50 } 50 }
51 51
52 // The buffer itself. It is not of type T because we don't want the 52 // The buffer itself. It is not of type T because we don't want the
53 // constructors and destructors to be automatically called. Define a POD 53 // constructors and destructors to be automatically called. Define a POD
54 // buffer of the right size instead. 54 // buffer of the right size instead.
55 base::AlignedMemory<sizeof(T[stack_capacity]), ALIGNOF(T)> stack_buffer_; 55 base::AlignedMemory<ALIGNOF(T), sizeof(T[stack_capacity])> stack_buffer_;
56 #if defined(OS_ANDROID) 56 #if defined(OS_ANDROID)
57 COMPILE_ASSERT(ALIGNOF(T) <= 16, crbug_115612); 57 COMPILE_ASSERT(ALIGNOF(T) <= 16, crbug_115612);
58 #endif 58 #endif
59 59
60 // Set when the stack buffer is used for an allocation. We do not track 60 // Set when the stack buffer is used for an allocation. We do not track
61 // how much of the buffer is used, only that somebody is using it. 61 // how much of the buffer is used, only that somebody is using it.
62 bool used_stack_buffer_; 62 bool used_stack_buffer_;
63 }; 63 };
64 64
65 // Used by containers when they want to refer to an allocator of type U. 65 // Used by containers when they want to refer to an allocator of type U.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 // Vectors are commonly indexed, which isn't very convenient even with 243 // Vectors are commonly indexed, which isn't very convenient even with
244 // operator-> (using "->at()" does exception stuff we don't want). 244 // operator-> (using "->at()" does exception stuff we don't want).
245 T& operator[](size_t i) { return this->container().operator[](i); } 245 T& operator[](size_t i) { return this->container().operator[](i); }
246 const T& operator[](size_t i) const { 246 const T& operator[](size_t i) const {
247 return this->container().operator[](i); 247 return this->container().operator[](i);
248 } 248 }
249 }; 249 };
250 250
251 #endif // BASE_STACK_CONTAINER_H_ 251 #endif // BASE_STACK_CONTAINER_H_
OLDNEW
« base/memory/aligned_memory.h ('K') | « base/memory/singleton.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698