Repository navigation
Modern SharedPtr SharedPtr
Paul Squires edited this page Oct 19, 2026
·
5 revisions
Home › Smart Pointers › SharedPtr and WeakPtr › SharedPtr
Holds an object shared by several owners and destroys it when the last one lets go.
SharedPtr( of T )- The object is destroyed exactly once, when the last handle goes away -- at scope exit, on reassignment, or when a container holding it is destroyed. No
deleteat the call site and no ownership convention to document. -
Two allocations per object, not C++'s one: the control block and the object are separate. Fusing them would make the control block generic, and since every member of a generic is instantiated whether called or not, that would require
Tto be default-constructible for every use -- including the ones that adopt an already-built pointer. - Under
-mtthe counts are atomic. That covers the control block, never the pointee: two threads may copy and destroy handles freely, but two threads calling a mutating member of the object still need their own lock. Exactly C++'s contract. - No comparison operators -- compare
Get( )for identity.
#import "std/memory"
using memory
type Node
as int32 id
end type
dim p as SharedPtr( of Node ) = MakeShared( of Node )( )
p.Ref( ).id = 7
print p.UseCount( ) '' 1
scope
dim q as SharedPtr( of Node ) = p
print p.UseCount( ) '' 2
end scope
print p.UseCount( ) '' 1 -- and the object is still alive
print p.Ref( ).id '' 7Library: SharedPtr and WeakPtr
Category: Smart Pointers
Documented under: Members
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing