docs
Docs
C++ API
C API
Search API
Ctrl K
1.4
2.0
latest
1.4
Ultralight C API
1.4.0
Toggle main menu visibility
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
23
#include <
Ultralight/CAPI/CAPI_Defines.h
>
24
25
#ifdef __cplusplus
26
extern
"C"
{
27
#endif
28
29
typedef
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
///
45
ULExport
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
///
51
ULExport
ULBuffer
ulCreateBufferFromCopy
(
const
void
* data,
size_t
size);
52
53
///
54
/// Destroy buffer (you should destroy any buffers you explicitly Create).
55
///
56
ULExport
void
ulDestroyBuffer
(
ULBuffer
buffer);
57
58
///
59
/// Get a pointer to the raw byte data.
60
///
61
ULExport
void
*
ulBufferGetData
(
ULBuffer
buffer);
62
63
///
64
/// Get the size in bytes.
65
///
66
ULExport
size_t
ulBufferGetSize
(
ULBuffer
buffer);
67
68
///
69
/// Get the user data associated with this Buffer, if any.
70
///
71
ULExport
void
*
ulBufferGetUserData
(
ULBuffer
buffer);
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
///
78
ULExport
bool
ulBufferOwnsData
(
ULBuffer
buffer);
79
80
#ifdef __cplusplus
81
}
// extern "C"
82
#endif
83
84
#endif
// ULTRALIGHT_CAPI_BUFFER_H
ulBufferOwnsData
bool ulBufferOwnsData(ULBuffer buffer)
Check whether this Buffer owns its own data (Buffer was created via ulCreateBufferFromCopy).
ulDestroyBufferCallback
void(*) ulDestroyBufferCallback(void *user_data, void *data)
Definition
CAPI_Buffer.h:29
ulBufferGetData
void * ulBufferGetData(ULBuffer buffer)
Get a pointer to the raw byte data.
ulBufferGetSize
size_t ulBufferGetSize(ULBuffer buffer)
Get the size in bytes.
ulDestroyBuffer
void ulDestroyBuffer(ULBuffer buffer)
Destroy buffer (you should destroy any buffers you explicitly Create).
ulBufferGetUserData
void * ulBufferGetUserData(ULBuffer buffer)
Get the user data associated with this Buffer, if any.
ulCreateBufferFromCopy
ULBuffer ulCreateBufferFromCopy(const void *data, size_t size)
Create a Buffer from existing data, a deep copy of data will be made.
ulCreateBuffer
ULBuffer ulCreateBuffer(void *data, size_t size, void *user_data, ulDestroyBufferCallback destruction_callback)
Create a Buffer from existing, user-owned data without any copies.
CAPI_Defines.h
Various defines and utility functions for the C API.
ULExport
#define ULExport
Definition
CAPI_Defines.h:38
ULBuffer
struct C_Buffer * ULBuffer
Definition
CAPI_Defines.h:66
Ultralight
CAPI
CAPI_Buffer.h
Docs
C++ API
C API
Version
1.4
2.0
latest
1.4