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