DanielSokil (2) [Avatar] Offline
Hello, What is a good example of when to use reference types vs non-reference types?

Here is a non-ref object:
    Person = object
        name: string
        age: int

var person: Person
person.name = "Daniel"

Here is a ref object:
    PersonObj = object
        name: string
        age: int
    PersonRef = ref PersonObj # reference type

proc setName(name: string, person: PersonRef) =
    person.name = name

var person1 = PersonRef()
setName("Daniel", person1)

Why should I use one over the other? They both seem to be achieving the same thing.
Since ref object is live on the heap, and non-ref is on the stack, Is that the only difference?
dom96 (75) [Avatar] Offline
This should help you out: https://forum.nim-lang.org/t/1207
DanielSokil (2) [Avatar] Offline
Thanks, Dominik!