Skip to content

Replace naked with smart pointers in the SofaDistanceGrid plugin #15

@th-skam

Description

@th-skam

The plugin could benefit from the use of smart pointers. There are many instances were naked pointers to the DistanceGrid object are being used by various components in the plugin. Their use is self-contained and seems well-managed. However, smart pointers could

  • Reduce some bulk code in destructors and similar methods
  • Relieve classes from managing memory directly

Replacements should be made in the following classes:

  • DistanceGrid
  • DistanceGridCollisionModel
  • RigidDistanceGridIntersection and FFDDistanceGridIntersection
  • DistanceGridForceField

Note

The DistanceGrid uses a static std::map to hold references to DistanceGrid instances and centrally manage memory. This is so that all components that make use of the same grid do not duplicate the allocation and use the existing (allocated) grid instead. The DistanceGrid class holds a reference count and increments/decrements the counter whenever it gives/takes access to the allocated grid to other components. It deletes itself from the static map once all instances have been destroyed. A combination of shared and weak pointers can do this.
Behaviour should be replicated not altered.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions