• Sylvartas@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    10
    ·
    edit-2
    11 hours ago

    Most of the time you pass by reference for more outputs, or by const ref to avoid copying a big-ass data structure (which is not always straightforward, with structures smaller than a pointer, which are pretty big in 64 bits architecture, you lose more to the ref overhead than to the copy IIRC)

    • DahGangalang@infosec.pub
      link
      fedilink
      arrow-up
      4
      ·
      11 hours ago

      Another reason I commonly see: to change the structure / “main pointer” to a data structure (esp during freeing and cleanup).