refc_binary.c

Include dependency graph for refc_binary.c:

digraph { graph [bgcolor="#00000000"] node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2] edge [color="#1414CE"] "4" [label="stdbool.h" tooltip="stdbool.h"] "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" fillcolor="#BFBFBF"] "30" [label="erl_nif_priv.h" tooltip="erl_nif_priv.h"] "3" [label="refc_binary.h" tooltip="refc_binary.h"] "21" [label="atom.h" tooltip="atom.h"] "9" [label="assert.h" tooltip="assert.h"] "29" [label="dictionary.h" tooltip="dictionary.h"] "14" [label="utils.h" tooltip="utils.h"] "17" [label="synclist.h" tooltip="synclist.h"] "5" [label="list.h" tooltip="list.h"] "12" [label="stdint.h" tooltip="stdint.h"] "2" [label="stdlib.h" tooltip="stdlib.h"] "19" [label="context.h" tooltip="context.h"] "13" [label="memory.h" tooltip="memory.h"] "6" [label="resources.h" tooltip="resources.h"] "24" [label="term.h" tooltip="term.h"] "15" [label="stddef.h" tooltip="stddef.h"] "7" [label="erl_nif.h" tooltip="erl_nif.h"] "10" [label="limits.h" tooltip="limits.h"] "22" [label="atom_table.h" tooltip="atom_table.h"] "25" [label="sys/types.h" tooltip="sys/types.h"] "26" [label="string.h" tooltip="string.h"] "8" [label="term_typedef.h" tooltip="term_typedef.h"] "20" [label="globalcontext.h" tooltip="globalcontext.h"] "18" [label="smp.h" tooltip="smp.h"] "28" [label="timer_list.h" tooltip="timer_list.h"] "31" [label="tempstack.h" tooltip="tempstack.h"] "27" [label="mailbox.h" tooltip="mailbox.h"] "32" [label="trace.h" tooltip="trace.h"] "16" [label="stdio.h" tooltip="stdio.h"] "23" [label="ets.h" tooltip="ets.h"] "11" [label="inttypes.h" tooltip="inttypes.h"] "1" -> "2" [dir=forward tooltip="include"] "1" -> "3" [dir=forward tooltip="include"] "1" -> "19" [dir=forward tooltip="include"] "1" -> "29" [dir=forward tooltip="include"] "1" -> "30" [dir=forward tooltip="include"] "1" -> "13" [dir=forward tooltip="include"] "1" -> "31" [dir=forward tooltip="include"] "1" -> "14" [dir=forward tooltip="include"] "1" -> "32" [dir=forward tooltip="include"] "30" -> "19" [dir=forward tooltip="include"] "30" -> "13" [dir=forward tooltip="include"] "30" -> "6" [dir=forward tooltip="include"] "3" -> "4" [dir=forward tooltip="include"] "3" -> "2" [dir=forward tooltip="include"] "3" -> "5" [dir=forward tooltip="include"] "3" -> "6" [dir=forward tooltip="include"] "21" -> "12" [dir=forward tooltip="include"] "21" -> "2" [dir=forward tooltip="include"] "29" -> "5" [dir=forward tooltip="include"] "29" -> "24" [dir=forward tooltip="include"] "14" -> "15" [dir=forward tooltip="include"] "14" -> "16" [dir=forward tooltip="include"] "14" -> "2" [dir=forward tooltip="include"] "17" -> "16" [dir=forward tooltip="include"] "17" -> "5" [dir=forward tooltip="include"] "17" -> "18" [dir=forward tooltip="include"] "5" -> "4" [dir=forward tooltip="include"] "19" -> "20" [dir=forward tooltip="include"] "19" -> "5" [dir=forward tooltip="include"] "19" -> "27" [dir=forward tooltip="include"] "19" -> "18" [dir=forward tooltip="include"] "19" -> "24" [dir=forward tooltip="include"] "19" -> "28" [dir=forward tooltip="include"] "13" -> "12" [dir=forward tooltip="include"] "13" -> "2" [dir=forward tooltip="include"] "13" -> "7" [dir=forward tooltip="include"] "13" -> "8" [dir=forward tooltip="include"] "13" -> "14" [dir=forward tooltip="include"] "6" -> "2" [dir=forward tooltip="include"] "6" -> "7" [dir=forward tooltip="include"] "6" -> "5" [dir=forward tooltip="include"] "6" -> "13" [dir=forward tooltip="include"] "6" -> "17" [dir=forward tooltip="include"] "24" -> "25" [dir=forward tooltip="include"] "24" -> "4" [dir=forward tooltip="include"] "24" -> "12" [dir=forward tooltip="include"] "24" -> "16" [dir=forward tooltip="include"] "24" -> "2" [dir=forward tooltip="include"] "24" -> "26" [dir=forward tooltip="include"] "24" -> "13" [dir=forward tooltip="include"] "24" -> "3" [dir=forward tooltip="include"] "24" -> "14" [dir=forward tooltip="include"] "24" -> "8" [dir=forward tooltip="include"] "7" -> "8" [dir=forward tooltip="include"] "22" -> "4" [dir=forward tooltip="include"] "22" -> "21" [dir=forward tooltip="include"] "8" -> "9" [dir=forward tooltip="include"] "8" -> "10" [dir=forward tooltip="include"] "8" -> "11" [dir=forward tooltip="include"] "8" -> "12" [dir=forward tooltip="include"] "20" -> "12" [dir=forward tooltip="include"] "20" -> "21" [dir=forward tooltip="include"] "20" -> "22" [dir=forward tooltip="include"] "20" -> "7" [dir=forward tooltip="include"] "20" -> "23" [dir=forward tooltip="include"] "20" -> "5" [dir=forward tooltip="include"] "20" -> "27" [dir=forward tooltip="include"] "20" -> "18" [dir=forward tooltip="include"] "20" -> "17" [dir=forward tooltip="include"] "20" -> "24" [dir=forward tooltip="include"] "20" -> "28" [dir=forward tooltip="include"] "18" -> "4" [dir=forward tooltip="include"] "28" -> "4" [dir=forward tooltip="include"] "28" -> "12" [dir=forward tooltip="include"] "28" -> "5" [dir=forward tooltip="include"] "27" -> "4" [dir=forward tooltip="include"] "27" -> "5" [dir=forward tooltip="include"] "27" -> "8" [dir=forward tooltip="include"] "27" -> "14" [dir=forward tooltip="include"] "23" -> "5" [dir=forward tooltip="include"] "23" -> "17" [dir=forward tooltip="include"] "23" -> "24" [dir=forward tooltip="include"] }

Functions

struct RefcBinary *refc_binary_create_resource(size_t size, struct ResourceType *resource_type)

Create a reference-counted resource object outside of the process heap.

This function will create a reference-counted resource object outside of the context heap. A blob will be allocated in the VM memory (e.g., via malloc). The allocated data will include an internal data structure that includes the data size and reference count.

Parameters:
  • size – the size of the data to create

  • resource_type – the resource type, NULL for regular refc binaries.

Returns:

a pointer to the out-of-context data.

const char *refc_binary_get_data(const struct RefcBinary *refc)

get the data of the off-context binary

Return the data of the off-context binary

Parameters:
  • ptr – Refc binary returned from memory_create_refc_binary

struct RefcBinary *refc_binary_from_data(void *ptr)

get the refc binary from its pointer

This must only be passed the result of refc_binary_get_data.

Parameters:
  • ptr – pointer obtained from refc_binary_get_data

void refc_binary_increment_refcount(struct RefcBinary *refc)

Increment the reference count on the refc binary.

Parameters:
  • ptr – the refc binary

bool refc_binary_decrement_refcount(struct RefcBinary *refc, struct GlobalContext *global)

Decrement the reference count on the refc binary.

This function will call refc_binary_destroy if the reference count reaches 0.

Parameters:
  • ptr – the refc binary

  • global – the global context

Returns:

true if the refc binary was free’d; false, otherwise

void refc_binary_destroy(struct RefcBinary *refc, struct GlobalContext *global)

Destroy a refc binary after its reference count reached 0.

This function will call the destructor if the refc binary is a resource and will free the refc binary.

Parameters:
  • refc – the binary to destroy

  • global – the global context

term refc_binary_create_binary_info(Context *ctx)

TODO consider implementing erlang:memory/0,1 instead

size_t refc_binary_total_size(Context *ctx)

Return the total size (in bytes) of all reference counted binaries.

Returns:

the total size (in bytes) of all reference counted binaries