Nim for Beginners #26 Reference Objects

Опубликовано: 04 Май 2026
на канале: Kiloneie
1,827
69

In this video i will teach you about Reference Objects. (BTW Nim's Garbage Collector is Reference Counting/Deterministic)

IMPORTANT NOTE: Since v2.0 you can now assign default values to fields of `objects`:
MyObject = object
data: string = "Some string"
name = "Yes this works too"

Version used: 1.4.8
Compiler settings used: --gc:orc(now called mm:orc | and is now the default)

Timestamps:
00:00 Intro and chapters of this video along with setting compiler flags to use GC ORC(incredible garbage collector)
00:32 Reference Object Definition
01:34 "repr" procedure for outputting advanced data types(Outputs full string representation)
02:01 Dereferencing a reference object(For outputting only the specified value)
03:06 Reference objects are passed by reference
03:58 new() procedure for reference types
05:04 Reference object use cases: Shared ownership
06:28 Nim's memory management(Nim uses a multi-paradim memory model)
08:02 Values created on the stack
08:38 Values created on the heap
10:40 Brief mention of .acyclic and .cursor annotations(very useful for optimization = performance)

Links:
Patreon page: https://www.patreon.com/Kiloneie?fan_...
Twitter page:   / kiloneie  
Code link: https://play.nim-lang.org/#ix=3yN4
Code documentation/offline tutorial: https://play.nim-lang.org/#ix=3yS9
Visual Studio Code Short Cuts: https://code.visualstudio.com/shortcu...

LINKS to this video's subject:
Introduction to ARC/ORC: https://nim-lang.org/blog/2020/10/15/...
Introducing ORC: https://nim-lang.org/blog/2020/12/08/...
Nim's memory management: https://nim-lang.org/docs/gc.html

zevv's more in depth blog post on Nim's memory: http://zevv.nl/nim-memory/
.acyclic annotation: https://nim-lang.org/docs/manual.html...
.cursor annotation: https://nim-lang.org/docs/destructors...