Archived

This topic is now archived and is closed to further replies.

delete with 2d array

This topic is 5200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all, I''ve got troubles using "massive" delete(s) ; I''ve got a 2d array containing POINTERS to some Vertex (my class name) objects. I try to delete a part of the array and then to replace each erased Vertex with a new DVertex (DVertex is derivated from the Vertex object). I''ve got an "access violation" occuring at random position (I think it''s random but I''m not sur) While debugging using VC6, the call stack contains -- Vertex::''scalar deleting destructor''unsigned int -- before the destructor. Dont know what it is... Questions : - "massive" deletes are ok ? - replace a pointer with a pointer of an derivated object is ok ? I post no code, cause my project starts to be very big ! It look''s like : class A {...}; class B : public A {...}; A *myArray[10][10]; for (a = 4 ; a < 6 ; a++) for (b = 4 ; b < 6 ; b++) { delete myArrayLink

Share on other sites
Oh, the bliss of using STL::vector (and boost::shared_ptr) has caused me to forget the pain of this kind of delete...
Anyway if you are sure this is the way you want to go I suggest you declare a type (which will make everything much easier):
typedef A * APtr;APtr myArray[10][10];for(a = first; a < last; ++a){  for(b = first; b < last; ++b)  {    delete myArray[a][b];    myArray[a][b] = new B;  }}

But I still recommend you at least switch to using STL::vector, it''s so much more convenient .

Share on other sites
The thing is that I use STL::vector ! :D
Actually it''s a bit complexe, so I simplified the description. I use both 2d array and stl vector.

I cant see what the typedef changes ?!

Replace an object by a derivated one isn''t a problem ?

Share on other sites
Maybe if you post a snippet of your real code it would be easier to help you. Maybe what you think is the problem isn''t the problem at all.
A typedef changes the clarity of the code. I always use it in multi-dimensional arrays so it''s clear to me (and others) what is stored at each index.

Share on other sites
An access violation means you tried to delete a pointer which wasn''t pointing to anything useful. Check your initialization code to make sure that you initialize correctly.

George D. Filiotis

Share on other sites
quote:

I think you mean std::vector, gentlemen.

Yeah, thanks for the tip, but we already know. std is the namespace all C++ standard library should be in (even the old C standard lib). STL is a subspace of std, the Standard Template Library. It''s not a namespace, but a concept. But thank you for participating.

Share on other sites
quote:
Original post by amag
Yeah, thanks for the tip, but we already know.

Yes, that's why where you writing "STL::vector"...
quote:
Original post by amag
STL is a subspace of std, the Standard Template Library. It's not a namespace, but a concept. But thank you for participating.

You don't need to explain anything to me, dear.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on October 25, 2003 9:38:38 AM]

Share on other sites
quote:

You don''t need to explain anything to me, dear.

No, obviously it wouldn''t help.
I think you would win on cutting down on the bessewisser-crap. Thanks for another useful post.
/amag

Share on other sites
No, I just have a problem with people nitpicking, and especially when they doesn''t seem to know the full story (which means they are wrong in their nitpicking).

Share on other sites
quote:
Original post by amag
I just have a problem with people nitpicking

Yes, you obviously do.
quote:
Original post by amag
especially when they doesn't seem to know the full story

Are you saying that I "don't seem to know the full story"? God, children. Thank you, but I think I know enough.
quote:
Original post by amag
(which means they are wrong in their nitpicking).

How do you work that one out, then?

You made a little mistake. Everyone does. Get over it.
Now, that's more than enough flaming for one thread. Let's stop now.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on October 25, 2003 10:08:13 AM]

Share on other sites
quote:

You made a little mistake. Everyone does. Get over it.
Now, that''s more than enough flaming for one thread. Let''s stop now.

WTF, you twat. I wrote STL::vector intentionally (by using uppercase STL, making it clear it wasn''t the namespace std I was refering to) and I have clearly explained to you and everyone else why it''s just as correct as writing std::vector.
My only mistake was that I used double-colon instead of a minus, which would''ve hopefully protected me from nitpicking nitwits such as yourself.
quote:

Thank you, but I think I know enough.

It seems you know enough to start a flame-war, if that''s what you mean. It''s often the misinformed who nitpick on stuff and get these things started.

Share on other sites
quote:
Original post by Symphonic
An access violation means you tried to delete a pointer which wasn''t pointing to anything useful. Check your initialization code to make sure that you initialize correctly.

Also, you could breakpoint before each pointer is deleted and check the contents of the pointer. Windows will set the memory at the address a pointer was pointing to after it was deleted to a particular code

eg.
I delete p, *p now points at 0xfeefee

Thats not the actual code, I cant remember what they are off the top of my head, but a search in google will tell you. It may be that your deleting data thats already deleted

Share on other sites
Your down-fall was the fact that you used the scope resolution operator.

I am not going to respond to your insults. Have a nice day.

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on October 25, 2003 3:41:54 PM]