|
-
March 16th, 2009, 09:17 AM
#16
Re: Memory leak - arghh!
Drama over - I malloced instead.
-
March 16th, 2009, 09:27 AM
#17
Re: Memory leak - arghh!
 Originally Posted by richiebabes
Drama over - I malloced instead. 
That is no solution.
First, if that class is non-POD, you cannot create objects using malloc(). All malloc() does is allocate bytes, that's it. The only way to actually create an object is to either declare one, or create one dynamically using operator new.
Using malloc() is equivalent to having me dump all the parts of a car in front of you. You can't drive it, you can't open the door, but all the parts are on the floor sitting there. On the other hand, operator new (or declaring an object) is equivalent to having the car built, ready to drive, open the door etc.
Regards,
Paul McKenzie
-
March 16th, 2009, 09:31 AM
#18
Re: Memory leak - arghh!
 Originally Posted by richiebabes
Drama over - I malloced instead.
Granted, since you are creating an array of char, malloc() will work, but it is walking a tight rope to use malloc() in C++ since you could accidentally use it for a non-POD type.
Frankly, a far simpler and safer solution would be:
Code:
std::vector<char> chpts(sPoints.GetLength() + 1);
Now, you no longer need to worry about managing the memory for chpts, and if you do need a char*, just write &chpts[0].
-
March 16th, 2009, 09:37 AM
#19
-
March 16th, 2009, 09:46 AM
#20
Re: Memory leak - arghh!
 Originally Posted by laserlight
Granted, since you are creating an array of char, malloc() will work, but it is walking a tight rope to use malloc() in C++ since you could accidentally use it for a non-POD type.
I don't think it's an array of char that's being created, but an array of CShape. That sounds like it's non-POD, making the malloc() "solution" incorrect.
Regards,
Paul McKenzie
-
March 16th, 2009, 10:14 AM
#21
Re: Memory leak - arghh!
Ok you have all sorts of good advice. Now try to take it. Short of VNCing your desktop there is alot of good stuff here. Now empower yourself, and do it!
ahoodin
To keep the plot moving, that's why.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|