Re: finding out if pointer to memory is valid

Discussion in 'C++' started by Dhruv, Jun 27, 2003.

  1. Dhruv

    Dhruv Guest

    On Thu, 26 Jun 2003 12:13:52 -0700, Schelli wrote:

    > ok, i got 2 pointers pointing to same memory/object. with one of the
    > pointers i delete the object and i could set this pointer to NULL to
    > know that it was deleted, but the other pointer still remains pointed
    > there and does not "know" the memory was deleted. so if i now access
    > this memory i might get a crash !
    >
    > now if i switch codeguard (BC++ 6.0) on, he immediately says accessing
    > non reserved memory, or something like this, although the program does
    > not crash yet, well, sometimes it does, but thats by chance of course.
    >
    > can i somehow find out that the memory this pointer is pointing to was
    > deleted ? or do i just have to find a way to set the other pointer to
    > NULL so i know.


    You could use a reference to a pointer, so that if you set any one to NULL,
    all of them become NULL. I don't know if this will fit in with your design
    though.

    Regards,
    -Dhruv.
    Dhruv, Jun 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Natalie
    Replies:
    0
    Views:
    734
    Ron Natalie
    Jun 26, 2003
  2. Sin
    Replies:
    1
    Views:
    1,070
    Ron Natalie
    Jun 26, 2003
  3. Alexander Terekhov

    Re: finding out if pointer to memory is valid

    Alexander Terekhov, Jun 27, 2003, in forum: C++
    Replies:
    0
    Views:
    747
    Alexander Terekhov
    Jun 27, 2003
  4. Ron Natalie
    Replies:
    0
    Views:
    763
    Ron Natalie
    Jun 27, 2003
  5. sfs
    Replies:
    3
    Views:
    294
Loading...

Share This Page