Memory question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arepi
    New Member
    • Sep 2008
    • 62

    Memory question

    Hi,

    If I make en object and then en other whit the same name, might take the second a new place in memory or "overwrite" the old?

    Thanks!

    Arepi
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You can't have to objects with the same name in the same scope.

    If you have to objects with the same name in different scopes the one declared most locally is the one in use and they would not occupy the same memory address.

    Comment

    • Arepi
      New Member
      • Sep 2008
      • 62

      #3
      Thanks!

      Originally posted by Banfa
      You can't have to objects with the same name in the same scope..
      Its really logical but then I dont understand what happening in my program. I mean that I've a callback and if I call that makes a new object. Then I call again and again and makes always new object whit the same name but I never deleted at the end of callback. Then I see that I've always the actual object because I give all time other parameter to any datamembers so has other bahavior the new object whit the same name.

      Can anybody explain that?

      Thanks!

      Arepi

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        You are not creating objects with the same name, the second time the callback is called you are in a different scope. You are probably getting confused between pointers to objects and objects but it would be easier to tell if we could see your code.

        Comment

        • Arepi
          New Member
          • Sep 2008
          • 62

          #5
          The callback called whit event handling as press a key,
          This is the part of the callback fuction.

          Code:
           virtual void Execute(vtkObject *caller, unsigned long, void*)
              { 
               
          	Some code....
          
          	vtkSphereSource *sphere = vtkSphereSource::New();
          	sphere->SetThetaResolution(8);
          	sphere->SetPhiResolution(8);
          	sphere->SetRadius(3.0);
          
          	vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
          	sphereMapper->SetInput(sphere->GetOutput());
          	vtkActor *sphereActor = vtkActor::New();
          	sphereActor->SetMapper(sphereMapper);
          	sphereActor->GetProperty()->SetColor(1,0,0);
          	
          	sphereActor->SetPosition(picker->GetPickPosition());
          	renderer->AddActor(sphereActor);
          	window->Render();
          
          	Some code....
          		
              }

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            To Arepi: You have to rememeber that each call to a function causes a stack frame to be created. Your objects are created in that stack frame. Therefore, everytime you call the function, yio get a new stack frame and a new set of variables.

            When you refer to a variable by name, it is always the variable in the stack frame of the current call. To see the objects from previous calls, you would need their addresses and then you could see them.

            Comment

            Working...