lundi 2 juillet 2018

Smart Pointer behavior using *

I have the following code snippet:

QList<const GLMeshPtr*> meshList;
m_itemsList->getSelectedMeshes(meshList);

for (auto m : meshList)
{
    if (GLBodyPtr c = (*m)->getStandard()) {
        c->executeMeshFix();
    }
}

GLMeshPtr is set as in this typedef:

typedef std::smart_ptr<GLMesh> GLMeshPtr;

The definition of m_itemsList->getSelectedMeshes is:

void QMeshList::getSelectedMeshes(QList<const GLMeshPtr*>& list)
{
    for (auto& m : m_meshList) {
        if (m->isSelected()) {
            list.push_back(m->getGLMesh());
        }
    }
}

Definition for getGLMesh is:

const GLMeshPtr* getGLMesh() const { return &m_glmesh; } // where m_glmesh is a GLMeshPtr.

My question is very simple, yet, I couldn't find any reference to it. Does the * keyword create a copy of the value in the stack, necessarily, or does it use the value "in place"?

I talk more specifically about this line:

if (GLBodyPtr c = (*m)->getStandard()) {

Am I creating unnecessary copies of GLBodyPtr? I don't want anyone here to share the pointer.

Aucun commentaire:

Enregistrer un commentaire