Wednesday, June 20, 2007

Re: pointers are unique?

  If there is any possibility that there will still be references to an object elsewhere after it is deleted, it should not be deleted in the first place; this is not a problem with pointers but rather with the design of your program.
  You would have to give a more in-depth description of the program (and, especially, what should happen when a node is deleted) in order for us to give a recommendation of what to do with your garbage-pointers.

  -BlueRaja


On 6/20/07, Saurabh Saha <saursaha@gmail.com> wrote:
Hi George
 
I completely agree with you but the doubt that I possess is how do you plan to allocate the same memory area that you freed because as soon as you free taht portion of the area, the area becomes a part of the free pool of memory space that is available to be allocated with of course the garbage values or values wrt the earlier object.
 
Now what exactly is the probability that a new node will take up exactly the same area that you freed in the last node as now it is not about the memory area but the picture is rather the free pool of memory in the heap.
 
Now allocation of memory to the new node is the OS's responsibility and hence it takes care of it not the coder at the code level.Wat say????
 
 
Regards
Saurabh

 
On 6/20/07, gexarchakos <gexarchakos@gmail.com > wrote:

Many thanks Saurabh,

actually you are right, that's exactly what I meant. I think I agree
with your points...

I am building a network simulator and created a directional graph and
initially I was using the pointers as IDs. But now I expand the
simulator with dynamic insertion and deletion of nodes. This means
that a new node may take the same memory space as an old deleted one.
In this case, not updated pointers from other nodes to the old one
will actually point to the new node. If no new node is inserted in the
same memory space then these pointers will be broken, right?

That was the problem that generated the question.

Many thanks again,
--George

On Jun 20, 11:54 am, "Saurabh Saha" < saurs...@gmail.com> wrote:
> Hi George
>
> When u talk about deleting a memory address what exactly do u actually
> mean-It does not mean u delete any memory area but rather it means that u
> free portion of d dynamic memory which was allocated to the object at
> runtime so I believe there is of course a possibility that the same memory
> area can be taken up by another object unless of course the developer
> forgets to de allocate the memory allocated thus resulting in a memory leak.
>
> So talking about delete from the OS point of view does not quite mean that
> whatever u delete from th UI is actually deleted but rather that the
> reference entity pointing to d memory area gets allocated 2 Null permanently
> and hence cannot point to d memory area it was earlier pointing to.
>
> Correct me if i am wrong guys,.
>
> Regards
> Saurabh
>
> On 6/20/07, gexarchakos <gexarcha...@gmail.com> wrote:
>
>
>
> > Hello everyone,
>
> > just a question on pointers:
> > Assume that you dynamically allocate memory for an object. Sometime
> > later, you dynamically delete it...
> > Is there a possibility that another dynamically created object will
> > take the same memory address as one previously deleted? In that case,
> > pointers cannot work as IDs of objects, right?
>
> > To me it makes sense if there is such a possibility. I'd like your
> > opinion...
>
> > Thanks,
> > -- George





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to Cpp-Programming@googlegroups.com
To unsubscribe from this group, send email to Cpp-Programming-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Cpp-Programming?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

<< Home