 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
todma Guest
|
Posted: Thu Jul 27, 2006 2:14 am Post subject: possible bug class inheriting from vector<> |
|
|
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
|
Posted: Thu Jul 27, 2006 3:23 am Post subject: Re: possible bug class inheriting from vector<> |
|
|
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
|
Posted: Thu Jul 27, 2006 8:39 pm Post subject: Re: possible bug class inheriting from vector<> |
|
|
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
|
Posted: Fri Jul 28, 2006 1:57 am Post subject: Re: possible bug class inheriting from vector<> |
|
|
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 |
|
 |
|
|
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
|
|