tinyimg 1.0.0
Lightweight image manipulation library for Cloudflare Workers
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <stddef.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
27#define TINYIMG_MAX_PIXELS 16000000u
28
42#define TINYIMG_MAX_IMAGE_BYTES 33554432u
43
49#define TINYIMG_ALIGNMENT 16u
50
55#define TINYIMG_HEAP_MAX 67108864u
56
57#pragma region primitives
58
70void* tiny_memcpy(void* dest, const void* src, size_t n);
71
83void* tiny_memset(void* s, int c, size_t n);
84
97void* tiny_memmove(void* dest, const void* src, size_t n);
98
112int tiny_memcmp(const void* s1, const void* s2, size_t n);
113
114#pragma endregion
115
116#pragma region heap
117
132int tiny_heap_init(void* memory, size_t size);
133
145
152typedef struct {
154 size_t capacity;
156 size_t used;
158 size_t available;
160 size_t peak;
162 uint32_t blocks;
164 uint32_t free_blocks;
166
176
191void* tiny_alloc(size_t size);
192
204void* tiny_realloc(void* pointer, size_t size);
205
214void tiny_free(void* pointer);
215
222size_t tiny_alloc_size(const void* pointer);
223
224#pragma endregion
225
226#pragma region arena
227
233typedef struct {
235 void* chunk;
237 size_t used;
239
257void* tiny_arena_alloc(size_t size, size_t alignment);
258
265
274
282
289
290#pragma endregion
291
292#pragma region blobs
293
317
321#define TINYIMG_MAX_BLOBS 8
322
326#define TINYIMG_BLOB_ID_MAX 32
327
344 TinyBlobKind kind, const char* id, const uint8_t* data, size_t size
345);
346
356const uint8_t* tiny_blob_get(TinyBlobKind kind, const char* id, size_t* size);
357
374const uint8_t* tiny_blob_at(
375 TinyBlobKind kind, uint32_t index, const char** id, size_t* size
376);
377
386int tiny_blob_free(TinyBlobKind kind, const char* id);
387
392
393#pragma endregion
394
395#ifdef __cplusplus
396}
397#endif
const uint8_t * tiny_blob_get(TinyBlobKind kind, const char *id, size_t *size)
Looks up a resident blob.
void tiny_arena_mark(TinyArenaMark *mark)
Records the current arena position.
void * tiny_realloc(void *pointer, size_t size)
Resizes a block, moving it only when it cannot grow in place.
int tiny_memcmp(const void *s1, const void *s2, size_t n)
Replicates the behavior of the standard memcmp function, comparing the first n bytes of the memory ar...
TinyBlobKind
Kinds of data the library reads but does not ship.
Definition memory.h:303
@ TINYIMG_BLOB_FONT
A TrueType, OpenType, PSF or BDF face.
Definition memory.h:307
@ TINYIMG_BLOB_CASCADE
A packed detection cascade.
Definition memory.h:315
@ TINYIMG_BLOB_ICC
An ICC color profile.
Definition memory.h:311
void * tiny_memset(void *s, int c, size_t n)
Replicates the behavior of the standard memset function, filling the first n bytes of the memory area...
int tiny_blob_load(TinyBlobKind kind, const char *id, const uint8_t *data, size_t size)
Registers a blob under an id.
const uint8_t * tiny_blob_at(TinyBlobKind kind, uint32_t index, const char **id, size_t *size)
Walks the resident blobs of one kind.
void tiny_heap_bootstrap(void)
Installs the platform's default heap if no heap exists yet.
void tiny_arena_release(const TinyArenaMark *mark)
Rewinds the arena to a recorded position.
void tiny_free(void *pointer)
Returns a block to the heap, coalescing it with free neighbors.
void * tiny_alloc(size_t size)
Allocates a block from the heap.
int tiny_heap_init(void *memory, size_t size)
Installs a caller supplied block as the heap.
size_t tiny_arena_reserved(void)
Bytes the arena currently holds from the heap.
void * tiny_memcpy(void *dest, const void *src, size_t n)
Replicates the behavior of the standard memcpy function, copying n bytes from src to dest.
int tiny_blob_free(TinyBlobKind kind, const char *id)
Releases one resident blob.
int tiny_heap_stats(TinyHeapStats *stats)
Reads the current heap occupancy.
void * tiny_memmove(void *dest, const void *src, size_t n)
Replicates the behavior of the standard memmove function, copying n bytes from src to dest....
void tiny_arena_reset(void)
Releases every block the arena has handed out.
size_t tiny_alloc_size(const void *pointer)
Usable size of a block, which may exceed what was asked for.
void * tiny_arena_alloc(size_t size, size_t alignment)
Allocates a block from the arena, aligned to the requested boundary.
void tiny_blob_free_all(void)
Releases every resident blob.
A saved arena position.
Definition memory.h:233
size_t used
Definition memory.h:237
void * chunk
Definition memory.h:235
A snapshot of heap occupancy.
Definition memory.h:152
uint32_t free_blocks
Definition memory.h:164
size_t peak
Definition memory.h:160
size_t available
Definition memory.h:158
size_t capacity
Definition memory.h:154
size_t used
Definition memory.h:156
uint32_t blocks
Definition memory.h:162