Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_ZONE_H_ | 5 #ifndef VM_ZONE_H_ |
| 6 #define VM_ZONE_H_ | 6 #define VM_ZONE_H_ |
| 7 | 7 |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/handles.h" | 10 #include "vm/handles.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 // Create an empty zone and set is at the current zone for the Isolate. | 101 // Create an empty zone and set is at the current zone for the Isolate. |
| 102 explicit Zone(BaseIsolate* isolate); | 102 explicit Zone(BaseIsolate* isolate); |
| 103 | 103 |
| 104 // Delete all memory associated with the zone. | 104 // Delete all memory associated with the zone. |
| 105 ~Zone(); | 105 ~Zone(); |
| 106 | 106 |
| 107 // Allocate 'size' bytes of memory in the zone; expands the zone by | 107 // Allocate 'size' bytes of memory in the zone; expands the zone by |
| 108 // allocating new segments of memory on demand using 'new'. | 108 // allocating new segments of memory on demand using 'new'. |
| 109 uword Allocate(intptr_t size) { return zone_.Allocate(size); } | 109 uword Allocate(intptr_t size) { return zone_.Allocate(size); } |
| 110 | 110 |
| 111 // Allocate space for an array of 'length' elements of type T. | |
| 112 template <typename T> | |
| 113 T* AllocateArray(intptr_t length) { | |
| 114 return reinterpret_cast<T*>(Allocate(length * sizeof(T))); | |
| 115 } | |
|
srdjan
2012/05/12 00:00:55
Remove this code. Do the appropriate allocation co
Kevin Millikin (Google)
2012/05/15 11:51:44
OK, but I'm not sure why. Avoiding reinterpret_ca
srdjan
2012/05/15 22:05:32
I think there is only one place that needs it, the
| |
| 116 | |
| 111 // Allocate 'new_size' bytes of memory and copies 'old_size' bytes from | 117 // Allocate 'new_size' bytes of memory and copies 'old_size' bytes from |
| 112 // 'data' into new allocated memory. Uses current zone. | 118 // 'data' into new allocated memory. Uses current zone. |
| 113 uword Reallocate(uword data, intptr_t old_size, intptr_t new_size) { | 119 uword Reallocate(uword data, intptr_t old_size, intptr_t new_size) { |
| 114 return zone_.Reallocate(data, old_size, new_size); | 120 return zone_.Reallocate(data, old_size, new_size); |
| 115 } | 121 } |
| 116 | 122 |
| 117 // Compute the total size of this zone. This includes wasted space that is | 123 // Compute the total size of this zone. This includes wasted space that is |
| 118 // due to internal fragmentation in the segments. | 124 // due to internal fragmentation in the segments. |
| 119 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } | 125 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } |
| 120 | 126 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 } | 171 } |
| 166 | 172 |
| 167 // Check that the result has the proper alignment and return it. | 173 // Check that the result has the proper alignment and return it. |
| 168 ASSERT(Utils::IsAligned(result, kAlignment)); | 174 ASSERT(Utils::IsAligned(result, kAlignment)); |
| 169 return result; | 175 return result; |
| 170 } | 176 } |
| 171 | 177 |
| 172 } // namespace dart | 178 } // namespace dart |
| 173 | 179 |
| 174 #endif // VM_ZONE_H_ | 180 #endif // VM_ZONE_H_ |
| OLD | NEW |