Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move/copy mechanisms #8

Merged
merged 13 commits into from
Sep 12, 2020
Merged

Move/copy mechanisms #8

merged 13 commits into from
Sep 12, 2020

Conversation

kolayne
Copy link
Member

@kolayne kolayne commented Aug 8, 2020

Added or restricted move/copy mechanisms for classes. Fixes #3

Is blocked by #6. The current branch (move_copy_mechanisms) is based on refactoring_face_class, so the corresponding PR should be approved before approving this, and new commits at refactoring_face_class should be merged into the current branch if there are any

@kolayne
Copy link
Member Author

kolayne commented Aug 26, 2020

Hi! Looks like our conversation with Codacy support has finished. They verified that this was an issue on Codacy side (fix of which is already committed but not yet deployed to production) and suggested ignoring the issues for now. The PR is absolutely ready for a review!

@kolayne kolayne requested a review from tanya-kta August 26, 2020 17:34
@kolayne kolayne added the blocking Another issue or pull request is waiting for this to be closed label Aug 27, 2020
Copy link
Member

@tanya-kta tanya-kta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Found some issues and left comments

src/Face.cuh Outdated
__device__ Face &operator=(Face &&other) noexcept;

/**
* Face` object move constructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be back quote before Face`

{
if(this != &other)
{
vertices = malloc_and_copy(other.vertices, other.n_of_vertices);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field Face::vertices has type const SpacePoint. Other variables which were moved to private section of their classes have no const in their types or const was removed from the type. Does Face::vertices really need const in type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, note, that the actual type is const SpacePoint * (* is an important part). It is different from the const SpacePoint *const type (which would mean the field vertices can't be modified), but the actual time means that the content of the array can't be modified without replacing the whole array. If the field was const pointer, it would take away the opportunity to, for example, move a face into an existing one, but the pointer to const only prevents us from accidentally modifying the vertices array (vertices of an existing Face shouldn't change i. e. have a specific set of vertices, shouldn't they?). Because the field is private, it's already impossible to modify the array from outside of the Face class, but is still possible to modify it from inside, which shouldn't happen and is worth protecting.

The general rule is if you don't modify a variable, make it constant. This way you will get additional protection from your compiler

@@ -46,9 +67,6 @@ public:
/// Pointer-represented array of nodes on the map
MapNode *nodes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has just drawn my attention, it might be not the problem of this PR. I suppose field SimulationMap::nodes should be moved to private, because it should not be changed after its creation in SimulationMap constructor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a separate issue

Comment on lines 26 to 30
__device__ Polyhedron &Polyhedron::operator=(Polyhedron &&other) noexcept
{
if(this != &other)
{
faces = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polyhedron B has to be moved to Polyhedron A. If A was created earlier (move constructor is not called during the moving), then setting A.faces to nullptr will cause leak of memory that A.faces contained before moving B to A. Same to Face::vertices, MapNode::particle (I suppose) and SimulationMap::nodes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right (by the way, I think, your explanation could be easier to understand if you'd provide a code snippet with an example). And yes, this does work for all Polyhedron::faces, Face::vertices, MapNode::particle and SimulationMap::nodes. Thank you for the alarm!

Copy link
Member

@tanya-kta tanya-kta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Member

@tanya-kta tanya-kta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@tanya-kta tanya-kta merged commit 7f658c5 into master Sep 12, 2020
@tanya-kta tanya-kta deleted the move_copy_mechanisms branch September 12, 2020 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocking Another issue or pull request is waiting for this to be closed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy/move constructors for classes
2 participants