Ultralight C API 1.3.0
Loading...
Searching...
No Matches
CAPI_Buffer.h
Go to the documentation of this file.
1/******************************************************************************
2 * This file is a part of Ultralight, an ultra-portable web-browser engine. *
3 * *
4 * See <https://ultralig.ht> for licensing and more. *
5 * *
6 * (C) 2023 Ultralight, Inc. *
7 *****************************************************************************/
8#ifndef ULTRALIGHT_CAPI_BUFFER_H
9#define ULTRALIGHT_CAPI_BUFFER_H
10
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17typedef void (*ulDestroyBufferCallback)(void* user_data, void* data);
18
19///
20/// Create a Buffer from existing, user-owned data without any copies. An optional, user-supplied
21/// callback will be called to deallocate data upon destruction.
22///
23/// @param data A pointer to the data.
24///
25/// @param size Size of the data in bytes.
26///
27/// @param user_data Optional user data that will be passed to destruction_callback
28/// when the returned Buffer is destroyed.
29///
30/// @param destruction_callback Optional callback that will be called upon destruction. Pass a
31/// null pointer if you don't want to be informed of destruction.
32///
33ULExport ULBuffer ulCreateBuffer(void* data, size_t size, void* user_data,
34 ulDestroyBufferCallback destruction_callback);
35
36///
37/// Create a Buffer from existing data, a deep copy of data will be made.
38///
39ULExport ULBuffer ulCreateBufferFromCopy(const void* data, size_t size);
40
41///
42/// Destroy buffer (you should destroy any buffers you explicitly Create).
43///
45
46///
47/// Get a pointer to the raw byte data.
48///
50
51///
52/// Get the size in bytes.
53///
55
56///
57/// Get the user data associated with this Buffer, if any.
58///
60
61///
62/// Check whether this Buffer owns its own data (Buffer was created via ulCreateBufferFromCopy).
63/// If this is false, Buffer will call the user-supplied destruction callback to deallocate data
64/// when this Buffer instance is destroyed.
65///
67
68#ifdef __cplusplus
69} // extern "C"
70#endif
71
72#endif // ULTRALIGHT_CAPI_BUFFER_H
void(* ulDestroyBufferCallback)(void *user_data, void *data)
Definition CAPI_Buffer.h:17
ULExport size_t ulBufferGetSize(ULBuffer buffer)
Get the size in bytes.
ULExport ULBuffer ulCreateBuffer(void *data, size_t size, void *user_data, ulDestroyBufferCallback destruction_callback)
Create a Buffer from existing, user-owned data without any copies.
ULExport void * ulBufferGetData(ULBuffer buffer)
Get a pointer to the raw byte data.
ULExport void * ulBufferGetUserData(ULBuffer buffer)
Get the user data associated with this Buffer, if any.
ULExport ULBuffer ulCreateBufferFromCopy(const void *data, size_t size)
Create a Buffer from existing data, a deep copy of data will be made.
ULExport bool ulBufferOwnsData(ULBuffer buffer)
Check whether this Buffer owns its own data (Buffer was created via ulCreateBufferFromCopy).
ULExport void ulDestroyBuffer(ULBuffer buffer)
Destroy buffer (you should destroy any buffers you explicitly Create).
#define ULExport
Definition CAPI_Defines.h:27
struct C_Buffer * ULBuffer
Definition CAPI_Defines.h:55