Dynamic Fraction Library 1.0.0
Reference-counted arbitrary precision rational number library (MIT OR Unlicense)
Loading...
Searching...
No Matches
Functions
Reference Counting Functions

Functions for managing integer lifetime through reference counting. More...

Functions

di_int di_retain (di_int big)
 Increment reference count and return the same integer.
 
void di_release (di_int *big)
 Decrement reference count and free if zero.
 
size_t di_ref_count (di_int big)
 Get current reference count of an integer.
 

Detailed Description

Functions for managing integer lifetime through reference counting.

Function Documentation

◆ di_ref_count()

size_t di_ref_count ( di_int  big)

Get current reference count of an integer.

Parameters
bigInteger to query (may be NULL)
Returns
Current reference count, or 0 if big is NULL
Since
1.0.0
Note
Primarily for debugging and testing

Definition at line 1298 of file dynamic_int.h.

◆ di_release()

void di_release ( di_int big)

Decrement reference count and free if zero.

Parameters
bigPointer to integer handle (may be NULL or point to NULL)
Since
1.0.0
di_release(&num); // num becomes NULL, memory freed if ref_count was 1
struct di_int_internal * di_int
Integer handle for arbitrary precision integers.
di_int di_from_int32(int32_t value)
Create a new integer from a 32-bit signed integer.
void di_release(di_int *big)
Decrement reference count and free if zero.
Note
Always sets the handle to NULL after releasing
Safe to call with NULL pointer or NULL handle
See also
di_retain() for incrementing reference count

Definition at line 1285 of file dynamic_int.h.

◆ di_retain()

di_int di_retain ( di_int  big)

Increment reference count and return the same integer.

Parameters
bigInteger to retain (may be NULL)
Returns
Same integer handle, or NULL if input was NULL
Since
1.0.0
di_int original = di_from_int32(42); // ref_count = 1
di_int shared = di_retain(original); // ref_count = 2, same object
di_release(&original); // ref_count = 1, object still alive
di_release(&shared); // ref_count = 0, object freed
di_int di_retain(di_int big)
Increment reference count and return the same integer.
Note
Use this when you want to share the same integer instance
See also
di_release() for decrementing reference count
di_copy() for creating an independent copy

Definition at line 1279 of file dynamic_int.h.