Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
unit_test_custom_zone.h
Go to the documentation of this file.
1// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4
5#ifndef RUNTIME_VM_COMPILER_FFI_UNIT_TEST_CUSTOM_ZONE_H_
6#define RUNTIME_VM_COMPILER_FFI_UNIT_TEST_CUSTOM_ZONE_H_
7
8#include <vector>
9
10// We use a custom zone here which doesn't depend on VM internals (e.g. handles,
11// thread, ...)
12#if defined(RUNTIME_VM_ZONE_H_)
13#error "We want our own zone implementation"
14#endif
15#define RUNTIME_VM_ZONE_H_
16
17namespace dart {
18
19class Zone {
20 public:
21 Zone() {}
22 ~Zone();
23
24 template <class ElementType>
25 inline ElementType* Alloc(intptr_t length) {
26 return static_cast<ElementType*>(AllocUnsafe(sizeof(ElementType) * length));
27 }
28
29 template <class ElementType>
30 inline ElementType* Realloc(ElementType* old_array,
31 intptr_t old_length,
32 intptr_t new_length) {
33 void* memory = AllocUnsafe(sizeof(ElementType) * new_length);
34 memmove(memory, old_array, sizeof(ElementType) * old_length);
35 return static_cast<ElementType*>(memory);
36 }
37
38 template <class ElementType>
39 void Free(ElementType* old_array, intptr_t len) {}
40
41 void* AllocUnsafe(intptr_t size);
42
43 private:
44 Zone(const Zone&) = delete;
45 void operator=(const Zone&) = delete;
46 std::vector<void*> buffers_;
47};
48
49} // namespace dart
50
51#endif // RUNTIME_VM_COMPILER_FFI_UNIT_TEST_CUSTOM_ZONE_H_
void * AllocUnsafe(intptr_t size)
void Free(ElementType *old_array, intptr_t len)
ElementType * Realloc(ElementType *old_array, intptr_t old_length, intptr_t new_length)
ElementType * Alloc(intptr_t length)
size_t length