OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CC_BASE_CONTIGUOUS_CONTAINER_H_ | 5 #ifndef CC_BASE_CONTIGUOUS_CONTAINER_H_ |
6 #define CC_BASE_CONTIGUOUS_CONTAINER_H_ | 6 #define CC_BASE_CONTIGUOUS_CONTAINER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "cc/base/cc_export.h" | 17 #include "cc/base/base_export.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 // ContiguousContainer is a container which stores a list of heterogeneous | 21 // ContiguousContainer is a container which stores a list of heterogeneous |
22 // objects (in particular, of varying sizes), packed next to one another in | 22 // objects (in particular, of varying sizes), packed next to one another in |
23 // memory. Objects are never relocated, so it is safe to store pointers to them | 23 // memory. Objects are never relocated, so it is safe to store pointers to them |
24 // for the lifetime of the container (unless the object is removed). | 24 // for the lifetime of the container (unless the object is removed). |
25 // | 25 // |
26 // Memory is allocated in a series of buffers (with exponential growth). When an | 26 // Memory is allocated in a series of buffers (with exponential growth). When an |
27 // object is allocated, it is given only the space it requires (possibly with | 27 // object is allocated, it is given only the space it requires (possibly with |
28 // enough padding to preserve alignment), rather than the maximum possible size. | 28 // enough padding to preserve alignment), rather than the maximum possible size. |
29 // This allows small and large objects to coexist without wasting much space. | 29 // This allows small and large objects to coexist without wasting much space. |
30 // | 30 // |
31 // Since it stores pointers to all of the objects it allocates in a vector, it | 31 // Since it stores pointers to all of the objects it allocates in a vector, it |
32 // supports efficient iteration and indexing. However, for mutation the | 32 // supports efficient iteration and indexing. However, for mutation the |
33 // supported operations are limited to appending to, and removing from, the end | 33 // supported operations are limited to appending to, and removing from, the end |
34 // of the list. | 34 // of the list. |
35 // | 35 // |
36 // Clients should instantiate ContiguousContainer; ContiguousContainerBase is an | 36 // Clients should instantiate ContiguousContainer; ContiguousContainerBase is an |
37 // artifact of the implementation. | 37 // artifact of the implementation. |
38 | 38 |
39 class CC_EXPORT ContiguousContainerBase { | 39 class CC_BASE_EXPORT ContiguousContainerBase { |
40 protected: | 40 protected: |
41 explicit ContiguousContainerBase(size_t max_object_size); | 41 explicit ContiguousContainerBase(size_t max_object_size); |
42 ContiguousContainerBase(size_t max_object_size, size_t initial_size_bytes); | 42 ContiguousContainerBase(size_t max_object_size, size_t initial_size_bytes); |
43 ~ContiguousContainerBase(); | 43 ~ContiguousContainerBase(); |
44 | 44 |
45 size_t size() const { return elements_.size(); } | 45 size_t size() const { return elements_.size(); } |
46 bool empty() const { return !size(); } | 46 bool empty() const { return !size(); } |
47 size_t GetCapacityInBytes() const; | 47 size_t GetCapacityInBytes() const; |
48 size_t UsedCapacityInBytes() const; | 48 size_t UsedCapacityInBytes() const; |
49 size_t MemoryUsageInBytes() const; | 49 size_t MemoryUsageInBytes() const; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 DCHECK_EQ(aligned_size % alignment, 0u); | 181 DCHECK_EQ(aligned_size % alignment, 0u); |
182 DCHECK_GE(aligned_size, size); | 182 DCHECK_GE(aligned_size, size); |
183 DCHECK_LT(aligned_size, size + alignment); | 183 DCHECK_LT(aligned_size, size + alignment); |
184 return aligned_size; | 184 return aligned_size; |
185 } | 185 } |
186 }; | 186 }; |
187 | 187 |
188 } // namespace cc | 188 } // namespace cc |
189 | 189 |
190 #endif // CC_BASE_CONTIGUOUS_CONTAINER_H_ | 190 #endif // CC_BASE_CONTIGUOUS_CONTAINER_H_ |
OLD | NEW |