auto_ptr with arrays
#1
According to this http://stackoverflow.com/questions/65208...with-array and this http://forums.codeguru.com/showthread.php?t=406187

this
Code:
std::auto_ptr<char> ConvertedData(new char[ ExpectedSize ]);
is illegal.


Actually I've heard from other people that just using an auto_ptr is bad practice...
Reply
Thanks given by:
#2
yeah, my bad, auto_ptr is bad for arrays. But I don't think it's so bad for normal objects that you need to get rid of at scope end.

I'll rewrite those bad char arrays. Later. Ish.

Good catch. This might be the actual cause of some failures on some platforms (unfortunately it works in MSVC, probably even in GCC)
Reply
Thanks given by:
#3
I've replaced the auto_ptr usage for char arrays in the branch. I won't be porting that to the trunk, 'cause I think the branch is now in a much better shape than the trunk Wink

As for not using auto_ptr at all, I tend to disagree. It's much safer using it than not using anything at all, and it's safe enough in our context so that nothing else needs to be used.
The only reason we're using auto_ptr is its ability to delete data unless explicitly told not to. This coincides with our algorithms, producing data in buffers and throwing away those buffers if anything goes wrong. Since we're not using exceptions at all, exception safety is something we should be too concerned about - we know about them, alright, but we don't handle them anyway, so any exception will basically crash MCS, no point in deallocating memory before the crash Smile
Reply
Thanks given by:




Users browsing this thread: 4 Guest(s)