C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

possible bug class inheriting from vector<>

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
todma
Guest





PostPosted: Thu Jul 27, 2006 2:14 am    Post subject: possible bug class inheriting from vector<> Reply with quote



Hi,
I'm doing this, can someone suggest a better way?:

using namespace std;

typedef vector<POINT> TPointVector;

class CTracePoints : public TPointVector
{
public:
bool bIsClosed;
};

This is just to associate a property with a vector of points.

My problem seems to appear in the following situation:

CTracePoints m_vA; // points for one set
CTracePoints m_vB; // points for second set

......I add points to one vector
then m_vB = m_vA;

When this happens, it seems my memory is corrupt or something.
Can anyone suggest any changes?
thanks for looking!
Todd.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Thomas Tutone
Guest





PostPosted: Thu Jul 27, 2006 3:23 am    Post subject: Re: possible bug class inheriting from vector<> Reply with quote



todma wrote:

Quote:
Hi,
I'm doing this, can someone suggest a better way?:

using namespace std;

typedef vector<POINT> TPointVector;

What is a POINT? What is its definition?

Quote:
class CTracePoints : public TPointVector
{
public:
bool bIsClosed;
};

This is just to associate a property with a vector of points.

My problem seems to appear in the following situation:

CTracePoints m_vA; // points for one set
CTracePoints m_vB; // points for second set

.....I add points to one vector
then m_vB = m_vA;

When this happens, it seems my memory is corrupt or something.

How do you know?

Can you post reasonably short, compilable code that demonstrates the
behavior?

Best regards,

Tom


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
todma
Guest





PostPosted: Thu Jul 27, 2006 8:39 pm    Post subject: Re: possible bug class inheriting from vector<> Reply with quote



Thanks Hrayr and Tom

My problem was that I was doing cross-process memory allocate/delete.
Specifically calling delete from process1, after the original object
was allocated in process2's initialization. (cross windows dll calls).

darn
Todd.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
todma
Guest





PostPosted: Fri Jul 28, 2006 1:57 am    Post subject: Re: possible bug class inheriting from vector<> Reply with quote

Actually,
I allocated memory in a class constructor, in a thread,
then during 'Win32' message event handling, I deleted the memory.
Or during the message I allocated the memory,
and during program shutdown, the object was destroyed and memory
deallocated.
Thus in windows there is a potential big problem with memory allocation
used between event handlers and other threads of a program.
The solution seems to be to 'reserve' in program initialization, and
never allocate or delete the vector during the program's execution!
(until shutdown).
This really is bad, but i'll try to live with it!

Todd.

my constructor:
CTracer::CTracer()
{
m_vPointsA.reserve(MAX_TRACE_POINTS+1);
m_vPointsB.reserve(MAX_TRACE_POINTS+1);
m_vPointsC.reserve(MAX_TRACE_POINTS+1);
}
what a lot of fun.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.