| 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 IO_BUFFER_H_ | 5 #ifndef BIN_IO_BUFFER_H_ |
| 6 #define IO_BUFFER_H_ | 6 #define BIN_IO_BUFFER_H_ |
| 7 | 7 |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| 11 | 11 |
| 12 class IOBuffer { | 12 class IOBuffer { |
| 13 public: | 13 public: |
| 14 // Allocate an IO buffer dart object (of type Uint8List) backed by | 14 // Allocate an IO buffer dart object (of type Uint8List) backed by |
| 15 // an external byte array. | 15 // an external byte array. |
| 16 static Dart_Handle Allocate(intptr_t size, uint8_t **buffer); | 16 static Dart_Handle Allocate(intptr_t size, uint8_t **buffer); |
| 17 | 17 |
| 18 // Allocate IO buffer storage. | 18 // Allocate IO buffer storage. |
| 19 static uint8_t* Allocate(intptr_t size); | 19 static uint8_t* Allocate(intptr_t size); |
| 20 | 20 |
| 21 // Function for disposing of IO buffer storage. All backing storage | 21 // Function for disposing of IO buffer storage. All backing storage |
| 22 // for IO buffers must be freed using this function. | 22 // for IO buffers must be freed using this function. |
| 23 static void Free(void* buffer) { | 23 static void Free(void* buffer) { |
| 24 delete[] reinterpret_cast<uint8_t*>(buffer); | 24 delete[] reinterpret_cast<uint8_t*>(buffer); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Function for finalizing external byte arrays used as IO buffers. |
| 28 static void Finalizer(Dart_Handle handle, void* buffer) { |
| 29 Free(buffer); |
| 30 if (handle != NULL) { |
| 31 Dart_DeletePersistentHandle(handle); |
| 32 } |
| 33 } |
| 34 |
| 27 private: | 35 private: |
| 28 DISALLOW_ALLOCATION(); | 36 DISALLOW_ALLOCATION(); |
| 29 DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); | 37 DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); |
| 30 }; | 38 }; |
| 31 | 39 |
| 32 #endif // IO_BUFFER_H_ | 40 #endif // BIN_IO_BUFFER_H_ |
| OLD | NEW |