Skip to content

Modern SharedPtr MakeSharedFrom

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Smart Pointers › SharedPtr and WeakPtr › MakeSharedFrom

MakeSharedFrom

Creates a copy of a value on the heap and returns a SharedPtr to it.

Syntax

MakeSharedFrom( of T )

Examples

#import "std/memory"
using memory

type Node
    as int32 id
end type

dim seed as Node
seed.id = 42

'' Copy-constructs the heap object from an existing value
dim p as SharedPtr( of Node ) = MakeSharedFrom( seed )

print p.Ref( ).id            '' 42

'' It is a COPY -- changing the original does not touch the owned object
seed.id = 99
print p.Ref( ).id            '' 42

Library: SharedPtr and WeakPtr
Category: Smart Pointers
Documented under: Members

Clone this wiki locally