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

Unified Diff: runtime/vm/dart_api_state.h

Issue 10836061: Change the zone allocation api. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_state.h
===================================================================
--- runtime/vm/dart_api_state.h (revision 10253)
+++ runtime/vm/dart_api_state.h (working copy)
@@ -33,16 +33,30 @@
// Delete all memory associated with the zone.
~ApiZone() { }
- // Allocate 'size' bytes of memory in the zone; expands the zone by
- // allocating new segments of memory on demand using 'new'.
- uword Allocate(intptr_t size) { return zone_.Allocate(size); }
+ // Allocates an array sized to hold 'len' elements of type
+ // 'ElementType'. Checks for integer overflow when performing the
+ // size computation.
+ template <class ElementType>
+ ElementType* Alloc(intptr_t len) { return zone_.Alloc<ElementType>(len); }
- // Allocate 'new_size' bytes of memory and copies 'old_size' bytes from
- // 'data' into new allocated memory. Uses current zone.
- uword Reallocate(uword data, intptr_t old_size, intptr_t new_size) {
- return zone_.Reallocate(data, old_size, new_size);
+ // Allocates an array sized to hold 'len' elements of type
+ // 'ElementType'. The new array is initialized from the memory of
+ // 'old_array' up to 'old_len'.
+ template <class ElementType>
+ ElementType* Realloc(ElementType* old_array,
+ intptr_t old_len,
+ intptr_t new_len) {
+ return zone_.Realloc<ElementType>(old_array, old_len, new_len);
}
+ // Allocates 'size' bytes of memory in the zone; expands the zone by
+ // allocating new segments of memory on demand using 'new'.
+ //
+ // It is preferred to use Alloc<T>() instead, as that function can
+ // check for integer overflow. If you use AllocUnsafe, you are
+ // responsible for avoiding integer overflow yourself.
+ uword AllocUnsafe(intptr_t size) { return zone_.AllocUnsafe(size); }
+
// Compute the total size of this zone. This includes wasted space that is
// due to internal fragmentation in the segments.
intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698