Value.array_buffer


Description:

[ CCode ( has_construct_function = false ) ]
[ Version ( since = "2.38" ) ]
public Value.array_buffer (Context context, void* data, size_t size, DestroyNotify? destroy_notify, void* user_data)

Creates a new arraybuffer from existing data in memory.

The data is not copied: while this allows sharing data with JavaScript efficiently, the caller must ensure that the memory region remains valid until the newly created object is released by JSC.

Optionally, a destroy_notify callback can be provided, which will be invoked with user_data as parameter when the arraybuffer object is released. This is intended to be used for freeing resources related to the memory region which contains the data:

!<-- language="C" -->
GMappedFile *f = g_mapped_file_new (file_path, TRUE, NULL);
JSCValue *value = jsc_value_new_array_buffer (context,
g_mapped_file_get_contents (f), g_mapped_file_get_length (f),
(GDestroyNotify) g_mapped_file_unref, f);

Note that the user_data can be the same value as data:

!<-- language="C" -->
void *bytes = g_malloc0 (100);
JSCValue *value = jsc_value_new_array_buffer (context, bytes, 100, g_free, bytes);

Parameters:

context

A Context

data

Pointer to a region of memory.

size

Size in bytes of the memory region.

destroy_notify

destroy notifier for user_data.

user_data

user data.

Returns:

A Value, or null in case of exception.