Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reference counting
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===C++=== C++ does not perform reference-counting by default, fulfilling its philosophy of not adding functionality that might incur overheads where the user has not explicitly requested it. Objects that are shared but not owned can be accessed via a reference, raw pointer, or [[Iterator (C++)|iterator]] (a conceptual generalisation of pointers). However, by the same token, C++ provides native ways for users to opt-into such functionality: [[C++11]] provides reference counted [[smart pointers]], via the [[Shared ptr|{{code|std::shared_ptr}}]] class, enabling automatic shared memory-management of dynamically allocated objects. Programmers can use this in conjunction with [[weak pointer]]s (via [[Shared ptr|{{code|std::weak_ptr}}]]) to break cyclic dependencies. Objects that are dynamically allocated but not intended to be shared can have their lifetime automatically managed using a [[Shared ptr|{{code|std::unique_ptr}}]]. In addition, [[Move semantics|C++11's move semantics]] further reduce the extent to which reference counts need to be modified by removing the deep copy normally used when a function returns an object, as it allows for a simple copy of the pointer of said object.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)