Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duk_api_memory.c File Reference
#include "duk_internal.h"

Go to the source code of this file.

Functions

DUK_EXTERNAL void * duk_alloc_raw (duk_context *ctx, duk_size_t size)
 
DUK_EXTERNAL void duk_free_raw (duk_context *ctx, void *ptr)
 
DUK_EXTERNAL void * duk_realloc_raw (duk_context *ctx, void *ptr, duk_size_t size)
 
DUK_EXTERNAL void * duk_alloc (duk_context *ctx, duk_size_t size)
 
DUK_EXTERNAL void duk_free (duk_context *ctx, void *ptr)
 
DUK_EXTERNAL void * duk_realloc (duk_context *ctx, void *ptr, duk_size_t size)
 
DUK_EXTERNAL void duk_get_memory_functions (duk_context *ctx, duk_memory_functions *out_funcs)
 
DUK_EXTERNAL void duk_gc (duk_context *ctx, duk_uint_t flags)
 

Function Documentation

◆ duk_alloc()

DUK_EXTERNAL void * duk_alloc ( duk_context * ctx,
duk_size_t size )

Definition at line 31 of file duktape-1.5.2/src-separate/duk_api_memory.c.

31 {
32 duk_hthread *thr = (duk_hthread *) ctx;
33
35
36 return DUK_ALLOC(thr->heap, size);
37}
#define DUK_ASSERT_CTX_VALID(ctx)
#define DUK_ALLOC(heap, size)

References DUK_ALLOC, DUK_ASSERT_CTX_VALID, and duk_hthread::heap.

◆ duk_alloc_raw()

DUK_EXTERNAL void * duk_alloc_raw ( duk_context * ctx,
duk_size_t size )

Definition at line 7 of file duktape-1.5.2/src-separate/duk_api_memory.c.

7 {
8 duk_hthread *thr = (duk_hthread *) ctx;
9
11
12 return DUK_ALLOC_RAW(thr->heap, size);
13}
#define DUK_ALLOC_RAW(heap, size)

References DUK_ALLOC_RAW, DUK_ASSERT_CTX_VALID, and duk_hthread::heap.

◆ duk_free()

DUK_EXTERNAL void duk_free ( duk_context * ctx,
void * ptr )

Definition at line 39 of file duktape-1.5.2/src-separate/duk_api_memory.c.

39 {
40 duk_hthread *thr = (duk_hthread *) ctx;
41
43
44 DUK_FREE(thr->heap, ptr);
45}
#define DUK_FREE(heap, ptr)

References DUK_ASSERT_CTX_VALID, DUK_FREE, and duk_hthread::heap.

◆ duk_free_raw()

DUK_EXTERNAL void duk_free_raw ( duk_context * ctx,
void * ptr )

Definition at line 15 of file duktape-1.5.2/src-separate/duk_api_memory.c.

15 {
16 duk_hthread *thr = (duk_hthread *) ctx;
17
19
20 DUK_FREE_RAW(thr->heap, ptr);
21}
#define DUK_FREE_RAW(heap, ptr)

References DUK_ASSERT_CTX_VALID, DUK_FREE_RAW, and duk_hthread::heap.

◆ duk_gc()

DUK_EXTERNAL void duk_gc ( duk_context * ctx,
duk_uint_t flags )

Definition at line 81 of file duktape-1.5.2/src-separate/duk_api_memory.c.

81 {
82#ifdef DUK_USE_MARK_AND_SWEEP
83 duk_hthread *thr = (duk_hthread *) ctx;
84 duk_heap *heap;
85
86 DUK_UNREF(flags);
87
88 /* NULL accepted */
89 if (!ctx) {
90 return;
91 }
93 heap = thr->heap;
94 DUK_ASSERT(heap != NULL);
95
96 DUK_D(DUK_DPRINT("mark-and-sweep requested by application"));
98#else
99 DUK_D(DUK_DPRINT("mark-and-sweep requested by application but mark-and-sweep not enabled, ignoring"));
100 DUK_UNREF(ctx);
101 DUK_UNREF(flags);
102#endif
103}
DUK_INTERNAL_DECL duk_bool_t duk_heap_mark_and_sweep(duk_heap *heap, duk_small_uint_t flags)
#define NULL
Definition gmacros.h:924

References DUK_ASSERT, DUK_ASSERT_CTX_VALID, DUK_D, DUK_DPRINT, duk_heap_mark_and_sweep(), DUK_UNREF, duk_hthread::heap, and NULL.

◆ duk_get_memory_functions()

DUK_EXTERNAL void duk_get_memory_functions ( duk_context * ctx,
duk_memory_functions * out_funcs )

Definition at line 65 of file duktape-1.5.2/src-separate/duk_api_memory.c.

65 {
66 duk_hthread *thr = (duk_hthread *) ctx;
67 duk_heap *heap;
68
70 DUK_ASSERT(out_funcs != NULL);
71 DUK_ASSERT(thr != NULL);
72 DUK_ASSERT(thr->heap != NULL);
73
74 heap = thr->heap;
75 out_funcs->alloc_func = heap->alloc_func;
76 out_funcs->realloc_func = heap->realloc_func;
77 out_funcs->free_func = heap->free_func;
78 out_funcs->udata = heap->heap_udata;
79}
duk_realloc_function realloc_func
duk_alloc_function alloc_func

References duk_heap::alloc_func, duk_memory_functions::alloc_func, DUK_ASSERT, DUK_ASSERT_CTX_VALID, duk_heap::free_func, duk_memory_functions::free_func, duk_hthread::heap, duk_heap::heap_udata, NULL, duk_heap::realloc_func, duk_memory_functions::realloc_func, and duk_memory_functions::udata.

◆ duk_realloc()

DUK_EXTERNAL void * duk_realloc ( duk_context * ctx,
void * ptr,
duk_size_t size )

Definition at line 47 of file duktape-1.5.2/src-separate/duk_api_memory.c.

47 {
48 duk_hthread *thr = (duk_hthread *) ctx;
49
51
52 /*
53 * Note: since this is an exposed API call, there should be
54 * no way a mark-and-sweep could have a side effect on the
55 * memory allocation behind 'ptr'; the pointer should never
56 * be something that Duktape wants to change.
57 *
58 * Thus, no need to use DUK_REALLOC_INDIRECT (and we don't
59 * have the storage location here anyway).
60 */
61
62 return DUK_REALLOC(thr->heap, ptr, size);
63}
#define DUK_REALLOC(heap, ptr, newsize)

References DUK_ASSERT_CTX_VALID, DUK_REALLOC, and duk_hthread::heap.

◆ duk_realloc_raw()

DUK_EXTERNAL void * duk_realloc_raw ( duk_context * ctx,
void * ptr,
duk_size_t size )

Definition at line 23 of file duktape-1.5.2/src-separate/duk_api_memory.c.

23 {
24 duk_hthread *thr = (duk_hthread *) ctx;
25
27
28 return DUK_REALLOC_RAW(thr->heap, ptr, size);
29}
#define DUK_REALLOC_RAW(heap, ptr, newsize)

References DUK_ASSERT_CTX_VALID, DUK_REALLOC_RAW, and duk_hthread::heap.