Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
Garbage Collection

Detailed Description

Todo:
The Garbage collector really needs to be optimized.

Macros

#define REDUCT_GC_RETAIN(_reduct, _handle)
 Retain an item, preventing it from being collected by the GC.
 
#define REDUCT_GC_RETAIN_ITEM(_reduct, _item)
 Retain a item, preventing it from being collected by the GC.
 
#define REDUCT_GC_RELEASE(_reduct, _handle)
 Release a previously retained item, allowing it to be collected by the GC.
 

Functions

REDUCT_API void reduct_gc (reduct_t *reduct)
 Run the garbage collector.
 
REDUCT_API void reduct_gc_if_needed (reduct_t *reduct)
 Optionally run the garbage collector if the number of allocated blocks exceeds the threshold.
 

Macro Definition Documentation

◆ REDUCT_GC_RETAIN

#define REDUCT_GC_RETAIN (   _reduct,
  _handle 
)
Value:
do \
{ \
(void)(_reduct); \
reduct_handle_t __handle = (_handle); \
if (REDUCT_HANDLE_IS_ITEM(&__handle)) \
{ \
reduct_item_t* __item = REDUCT_HANDLE_TO_ITEM(&__handle); \
__item->retainCount++; \
} \
} while (0)
reduct_uint64_t reduct_handle_t
Handle type.
Definition defs.h:189
#define REDUCT_HANDLE_IS_ITEM(_handle)
Check if a handle is an item.
Definition handle.h:171
#define REDUCT_HANDLE_TO_ITEM(_handle)
Get the item pointer of a handle.
Definition handle.h:257
Item structure.
Definition item.h:57
reduct_uint16_t retainCount
The reference count for GC retention.
Definition item.h:62

Retain an item, preventing it from being collected by the GC.

Parameters
reductThe Reduct structure.
itemThe item to retain, must be a item.

Definition at line 38 of file gc.h.

◆ REDUCT_GC_RETAIN_ITEM

#define REDUCT_GC_RETAIN_ITEM (   _reduct,
  _item 
)
Value:
do \
{ \
(void)(_reduct); \
reduct_item_t* __item = (_item); \
__item->retainCount++; \
} while (0)

Retain a item, preventing it from being collected by the GC.

Parameters
reductThe Reduct structure.
itemThe item to retain.

Definition at line 56 of file gc.h.

◆ REDUCT_GC_RELEASE

#define REDUCT_GC_RELEASE (   _reduct,
  _handle 
)
Value:
do \
{ \
(void)(_reduct); \
reduct_handle_t __handle = (_handle); \
if (REDUCT_HANDLE_IS_ITEM(&__handle)) \
{ \
reduct_item_t* __item = REDUCT_HANDLE_TO_ITEM(&__handle); \
__item->retainCount--; \
} \
} while (0)

Release a previously retained item, allowing it to be collected by the GC.

Parameters
reductThe Reduct structure.
itemThe item to release.

Definition at line 70 of file gc.h.

Function Documentation

◆ reduct_gc()

REDUCT_API void reduct_gc ( reduct_t reduct)

Run the garbage collector.

Parameters
reductThe Reduct structure.

Definition at line 108 of file gc_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reduct_gc_if_needed()

REDUCT_API void reduct_gc_if_needed ( reduct_t reduct)

Optionally run the garbage collector if the number of allocated blocks exceeds the threshold.

Parameters
reductThe Reduct structure.

Definition at line 96 of file gc_impl.h.

Here is the call graph for this function:
Here is the caller graph for this function: