|
Blender V4.3
|
#include <BLI_implicit_sharing.hh>
Inherits blender::NonCopyable, and blender::NonMovable.
Inherited by CustomDataLayerImplicitSharing, blender::ImplicitSharedValue< T >, blender::ImplicitSharingMixin, and blender::implicit_sharing::MEMFreeImplicitSharing.
Public Member Functions | |
| virtual | ~ImplicitSharingInfo () |
| bool | is_mutable () const |
| bool | is_expired () const |
| void | add_user () const |
| void | add_weak_user () const |
| void | tag_ensured_mutable () const |
| int64_t | version () const |
| int | strong_users () const |
| void | remove_user_and_delete_if_last () const |
| void | remove_weak_user_and_delete_if_last () const |
#ImplicitSharingInfo is the core data structure for implicit sharing in Blender. Implicit sharing is a technique that avoids copying data when it is not necessary. This results in better memory usage and performance. Only read-only data can be shared, because otherwise multiple owners might want to change the data in conflicting ways.
To determine whether data is shared, #ImplicitSharingInfo keeps a user count. If the count is 1, the data only has a single owner and is therefore mutable. If some code wants to modify data that is currently shared, it has to make a copy first. This behavior is also called "copy on write".
In addition to containing the reference count, #ImplicitSharingInfo also knows how to destruct the referenced data. This is important because the code freeing the data in the end might not know how it was allocated (for example, it doesn't know whether an array was allocated using the system or guarded allocator).
#ImplicitSharingInfo can be used in two ways:
Definition at line 41 of file BLI_implicit_sharing.hh.
|
inlinevirtual |
Definition at line 66 of file BLI_implicit_sharing.hh.
References BLI_assert.
|
inline |
Call when a the data has a new additional owner.
Definition at line 88 of file BLI_implicit_sharing.hh.
References BLI_assert, and is_expired().
Referenced by blender::bke::GeometrySet::add(), BLO_write_shared(), blender::geometry::gather_realize_tasks_recursive(), and um_arraystore_cd_compact().
|
inline |
Adding a weak owner prevents the #ImplicitSharingInfo from being freed but not the referenced data.
Definition at line 102 of file BLI_implicit_sharing.hh.
Referenced by blender::tests::TEST(), and blender::bke::bake::BlobWriteSharing::write_implicitly_shared().
|
inline |
Weak users don't protect the referenced data from being freed. If the data is freed while there is still a weak referenced, this returns true.
Definition at line 82 of file BLI_implicit_sharing.hh.
Referenced by add_user(), blender::bke::CurveComponent::clear(), blender::bke::GeometryComponentEditData::clear(), blender::bke::GreasePencilComponent::clear(), blender::bke::InstancesComponent::clear(), blender::bke::MeshComponent::clear(), blender::bke::PointCloudComponent::clear(), blender::bke::VolumeComponent::clear(), and blender::tests::TEST().
|
inline |
Whether the resource can be modified in place because there is only one owner.
Definition at line 73 of file BLI_implicit_sharing.hh.
Referenced by blender::bke::CurveComponent::clear(), blender::bke::GeometryComponentEditData::clear(), blender::bke::GreasePencilComponent::clear(), blender::bke::InstancesComponent::clear(), blender::bke::MeshComponent::clear(), blender::bke::PointCloudComponent::clear(), blender::bke::VolumeComponent::clear(), blender::bke::CurveComponent::ensure_owns_direct_data(), blender::bke::GreasePencilComponent::ensure_owns_direct_data(), blender::bke::MeshComponent::ensure_owns_direct_data(), blender::bke::PointCloudComponent::ensure_owns_direct_data(), blender::bke::VolumeComponent::ensure_owns_direct_data(), blender::bke::CurveComponent::get_for_write(), blender::bke::GreasePencilComponent::get_for_write(), blender::bke::InstancesComponent::get_for_write(), blender::bke::MeshComponent::get_for_write(), blender::bke::PointCloudComponent::get_for_write(), blender::bke::VolumeComponent::get_for_write(), blender::bke::CurveComponent::release(), blender::bke::GreasePencilComponent::release(), blender::bke::InstancesComponent::release(), blender::bke::MeshComponent::release(), blender::bke::PointCloudComponent::release(), blender::bke::VolumeComponent::release(), blender::bke::CurveComponent::replace(), blender::bke::GreasePencilComponent::replace(), blender::bke::InstancesComponent::replace(), blender::bke::MeshComponent::replace(), blender::bke::PointCloudComponent::replace(), blender::bke::VolumeComponent::replace(), tag_ensured_mutable(), and blender::tests::TEST().
|
inline |
Call when the data is no longer needed. This might just decrement the user count, or it might also delete the data if this was the last user.
Definition at line 139 of file BLI_implicit_sharing.hh.
References BLI_assert, and remove_weak_user_and_delete_if_last().
Referenced by BKE_mesh_legacy_face_set_to_generic(), blender::bke::bake::load_attributes(), blender::bke::mesh_sculpt_mask_to_generic(), move_face_map_data_to_attributes(), and replace_custom_data_layer_with_named().
|
inline |
This might just decrement the weak user count or might delete the data. Should be used in conjunction with add_weak_user.
Definition at line 168 of file BLI_implicit_sharing.hh.
References BLI_assert.
Referenced by remove_user_and_delete_if_last(), and blender::tests::TEST().
|
inline |
Definition at line 130 of file BLI_implicit_sharing.hh.
Referenced by BLO_write_shared().
|
inline |
Call this when making sure that the referenced data is mutable, which also implies that it is about to be modified. This allows other code to detect whether data has not been changed very efficiently.
Definition at line 112 of file BLI_implicit_sharing.hh.
References BLI_assert, and is_mutable().
|
inline |
Get a version number that is increased when the data is modified. It can be used to detect if data has been changed.
Definition at line 125 of file BLI_implicit_sharing.hh.
Referenced by blender::tests::TEST(), and blender::bke::bake::BlobWriteSharing::write_implicitly_shared().