473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Memory question

62
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
Apr 11 '09 #1
5 1528
Banfa
9,065 Expert Mod 8TB
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.
Apr 12 '09 #2
Arepi
62
Thanks!

@Banfa
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
Apr 12 '09 #3
Banfa
9,065 Expert Mod 8TB
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.
Apr 13 '09 #4
Arepi
62
The callback called whit event handling as press a key,
This is the part of the callback fuction.

Expand|Select|Wrap|Line Numbers
  1.  virtual void Execute(vtkObject *caller, unsigned long, void*)
  2.     { 
  3.  
  4.     Some code....
  5.  
  6.     vtkSphereSource *sphere = vtkSphereSource::New();
  7.     sphere->SetThetaResolution(8);
  8.     sphere->SetPhiResolution(8);
  9.     sphere->SetRadius(3.0);
  10.  
  11.     vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
  12.     sphereMapper->SetInput(sphere->GetOutput());
  13.     vtkActor *sphereActor = vtkActor::New();
  14.     sphereActor->SetMapper(sphereMapper);
  15.     sphereActor->GetProperty()->SetColor(1,0,0);
  16.  
  17.     sphereActor->SetPosition(picker->GetPickPosition());
  18.     renderer->AddActor(sphereActor);
  19.     window->Render();
  20.  
  21.     Some code....
  22.  
  23.     }
Apr 13 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
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.
Apr 19 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: John | last post by:
Hi all: When I run my code, I find that the memory that the code uses keeps increasing. I have a PC with 2G RAM running Debian linux. The code consumes 1.5G memory by the time it finishes...
6
by: Fred Zwarts | last post by:
Hello, I am trying to debug some complex debug code. In order to track the use of dynamically allocated memory, I replaced the standard global new and delete operators. (Not for changing the...
20
by: Jonas | last post by:
Hi, I'm 99 % sure that Standard C guarantees to do a memory move inside realloc() in case the new, returned memory block (address) is different than the original one. Can any C expert confirm...
8
by: vikram | last post by:
i have series of questions 1.How a c program is loaded in memory i mean the whats is the structure that the code segment?? data segment?? 2.When you say const int *p; where is p...
30
by: jimjim | last post by:
Hello, This is a simple question for you all, I guess . int main(){ double *g= new double; *g = 9; delete g; cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; *g =...
18
by: Ramasubbu Ramasubramanian XR (AS/EAB) | last post by:
What is memory leakage, could any one explain with sample code
25
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My...
2
by: Ashish | last post by:
hi all, I have been doing some performance testing of a asp_net website, to be hosted on a shared server .. as far as i understand every page when accessed first time is compiled and loaded in...
7
by: toton | last post by:
Hi, I have a STL vector of of characters and the character class has a Boost array of points. The things are vector<Characterchars; and class Character{ private: array<Point,Npoints; }; Now...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.