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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/debugger.cc » ('j') | 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 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_DART_API_STATE_H_ 5 #ifndef VM_DART_API_STATE_H_
6 #define VM_DART_API_STATE_H_ 6 #define VM_DART_API_STATE_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 #include "platform/thread.h" 10 #include "platform/thread.h"
(...skipping 15 matching lines...) Expand all
26 // zones support deallocating all chunks in one fast operation when the 26 // zones support deallocating all chunks in one fast operation when the
27 // scope is exited. 27 // scope is exited.
28 class ApiZone { 28 class ApiZone {
29 public: 29 public:
30 // Create an empty zone. 30 // Create an empty zone.
31 ApiZone() : zone_() { } 31 ApiZone() : zone_() { }
32 32
33 // Delete all memory associated with the zone. 33 // Delete all memory associated with the zone.
34 ~ApiZone() { } 34 ~ApiZone() { }
35 35
36 // Allocate 'size' bytes of memory in the zone; expands the zone by 36 // Allocates an array sized to hold 'len' elements of type
37 // 'ElementType'. Checks for integer overflow when performing the
38 // size computation.
39 template <class ElementType>
40 ElementType* Alloc(intptr_t len) { return zone_.Alloc<ElementType>(len); }
41
42 // Allocates an array sized to hold 'len' elements of type
43 // 'ElementType'. The new array is initialized from the memory of
44 // 'old_array' up to 'old_len'.
45 template <class ElementType>
46 ElementType* Realloc(ElementType* old_array,
47 intptr_t old_len,
48 intptr_t new_len) {
49 return zone_.Realloc<ElementType>(old_array, old_len, new_len);
50 }
51
52 // Allocates 'size' bytes of memory in the zone; expands the zone by
37 // allocating new segments of memory on demand using 'new'. 53 // allocating new segments of memory on demand using 'new'.
38 uword Allocate(intptr_t size) { return zone_.Allocate(size); } 54 //
39 55 // It is preferred to use Alloc<T>() instead, as that function can
40 // Allocate 'new_size' bytes of memory and copies 'old_size' bytes from 56 // check for integer overflow. If you use AllocUnsafe, you are
41 // 'data' into new allocated memory. Uses current zone. 57 // responsible for avoiding integer overflow yourself.
42 uword Reallocate(uword data, intptr_t old_size, intptr_t new_size) { 58 uword AllocUnsafe(intptr_t size) { return zone_.AllocUnsafe(size); }
43 return zone_.Reallocate(data, old_size, new_size);
44 }
45 59
46 // Compute the total size of this zone. This includes wasted space that is 60 // Compute the total size of this zone. This includes wasted space that is
47 // due to internal fragmentation in the segments. 61 // due to internal fragmentation in the segments.
48 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); } 62 intptr_t SizeInBytes() const { return zone_.SizeInBytes(); }
49 63
50 private: 64 private:
51 BaseZone* GetBaseZone() { return &zone_; } 65 BaseZone* GetBaseZone() { return &zone_; }
52 66
53 BaseZone zone_; 67 BaseZone zone_;
54 68
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 ApiNativeScope::Current()->zone()->GetBaseZone()) {} 671 ApiNativeScope::Current()->zone()->GetBaseZone()) {}
658 ApiGrowableArray() 672 ApiGrowableArray()
659 : BaseGrowableArray<T, ValueObject>( 673 : BaseGrowableArray<T, ValueObject>(
660 ApiNativeScope::Current()->zone()->GetBaseZone()) {} 674 ApiNativeScope::Current()->zone()->GetBaseZone()) {}
661 }; 675 };
662 676
663 677
664 } // namespace dart 678 } // namespace dart
665 679
666 #endif // VM_DART_API_STATE_H_ 680 #endif // VM_DART_API_STATE_H_
OLDNEW
« 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