Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-05

smart pointers

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

I was trying to find some definitive answers on how smart pointers (will) work.

E.g. do smart pointers have a compiler controlled build in ref-counter like other managed types (strings/dyn-array).

It seems not, but info I found is a bit conflicting.

https://wiki.freepascal.org/smartpointers
- no build in refcount? (at least disassembler did not show any)

https://forum.lazarus.freepascal.org/index.php?topic=42028.0
- there is an "AddRef" but no info if there is a "DecRef"

https://fpc-devel.freepascal.narkive.com/KlDxttCU/pascal-smart-pointers-idea-arc-implementation
- there is a "copy" but neither "AddRef" nor "DecRef"

Also the last page speaks of a difference of "record operators" (which is what all the other pages seem to do?)
and an actual pointer "smart pointer"?

Though the smart pointer seems itself to be a record, with a user defined (not compiler added) refcount field?

Reply by email

Wayne Sherman
to Martin Frb
Show quoted text 5 lines
I was trying to find some definitive answers on how smart pointers (will) work. E.g. do smart pointers have a compiler controlled build in ref-counter like other managed types (strings/dyn-array). It seems not, but info I found is a bit conflicting.

https://wiki.freepascal.org/management_operators
"AddRef is called after the contents of a record have been duplicated by a bitwise copy (for example after, not during, an assignment.) By itself it does not do any lifetime management, but you can use it to implement it."

Reply by email

Martin Frb
to Wayne Sherman
Wayne Sherman wrote 11 lines
On Thu, May 28, 2026 at 1:05 AM Martin Frb wrote: > I was trying to find some definitive answers on how smart pointers > (will) work. > E.g. do smart pointers have a compiler controlled build in ref-counter > like other managed types (strings/dyn-array). > It seems not, but info I found is a bit conflicting. https://wiki.freepascal.org/management_operators "AddRef is called after the contents of a record have been duplicated by a bitwise copy (for example after, not during, an assignment.) By itself it does not do any lifetime management, but you can use it to implement it."

Thanks, so that is "managed operators" (and they allow (but don't force) refcounting, if the user adds there own refcount) => but no compiler magic refcount.

But then

https://fpc-devel.freepascal.narkive.com/KlDxttCU/pascal-smart-pointers-idea-arc-implementation

The second step is some concept of low level structures for smart pointers (in this conception we have two kinds of smart pointers - smart pointers for objects and smart pointers for pointers):

Has anything evolved of that? Is there are concept of smart pointers that goes beyond just wrapping another managed record around some data?

Or are there any plans?

The purpose is to establish a list of data-types that either has "hidden refcount", or will possible get that ...

Reply by email