Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
dart::bin::IOBuffer Class Reference

#include <io_buffer.h>

Static Public Member Functions

static Dart_Handle Allocate (intptr_t size, uint8_t **buffer)
 
static uint8_t * Allocate (intptr_t size)
 
static uint8_t * Reallocate (uint8_t *buffer, intptr_t new_size)
 
static void Free (void *buffer)
 
static void Finalizer (void *isolate_callback_data, void *buffer)
 

Detailed Description

Definition at line 14 of file io_buffer.h.

Member Function Documentation

◆ Allocate() [1/2]

uint8_t * dart::bin::IOBuffer::Allocate ( intptr_t  size)
static

Definition at line 30 of file io_buffer.cc.

30 {
31 return static_cast<uint8_t*>(calloc(size, sizeof(uint8_t)));
32}
void * calloc(size_t n, size_t size)
Definition allocation.cc:11

◆ Allocate() [2/2]

Dart_Handle dart::bin::IOBuffer::Allocate ( intptr_t  size,
uint8_t **  buffer 
)
static

Definition at line 12 of file io_buffer.cc.

12 {
13 uint8_t* data = Allocate(size);
14 if (data == nullptr) {
15 return Dart_Null();
16 }
19
20 if (Dart_IsError(result)) {
21 Free(data);
23 }
24 if (buffer != nullptr) {
25 *buffer = data;
26 }
27 return result;
28}
static void Free(void *buffer)
Definition io_buffer.h:28
static void Finalizer(void *isolate_callback_data, void *buffer)
Definition io_buffer.h:31
static Dart_Handle Allocate(intptr_t size, uint8_t **buffer)
Definition io_buffer.cc:12
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
@ Dart_TypedData_kUint8
Definition dart_api.h:2606
static const uint8_t buffer[]
GAsyncResult * result
DART_EXPORT Dart_Handle Dart_NewExternalTypedDataWithFinalizer(Dart_TypedData_Type type, void *data, intptr_t length, void *peer, intptr_t external_allocation_size, Dart_HandleFinalizer callback)
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_Null()
static int8_t data[kExtLength]

◆ Finalizer()

static void dart::bin::IOBuffer::Finalizer ( void *  isolate_callback_data,
void *  buffer 
)
inlinestatic

Definition at line 31 of file io_buffer.h.

31 {
32 Free(buffer);
33 }

◆ Free()

static void dart::bin::IOBuffer::Free ( void *  buffer)
inlinestatic

Definition at line 28 of file io_buffer.h.

28{ free(buffer); }

◆ Reallocate()

uint8_t * dart::bin::IOBuffer::Reallocate ( uint8_t *  buffer,
intptr_t  new_size 
)
static

Definition at line 34 of file io_buffer.cc.

34 {
35 // It seems windows realloc() and glibc relloc() don't free memory when
36 // shrinking, so we'll manually allocate a new buffer, copy the data and free
37 // the old buffer. This also avoids a corner case if the new size is 0:
38 // It can return `nullptr` in that case even though `malloc(0)` would
39 // return a unique non-`nullptr` value.
40 auto new_buffer = IOBuffer::Allocate(new_size);
41 if (new_buffer != nullptr) {
42 memmove(new_buffer, buffer, new_size);
43 free(buffer);
44 return static_cast<uint8_t*>(new_buffer);
45 }
46 return static_cast<uint8_t*>(realloc(buffer, new_size));
47}
void * realloc(void *ptr, size_t size)
Definition allocation.cc:27

The documentation for this class was generated from the following files: