Re: how to organize several class and their instance in windows programming
"asm23" <asmwarrior@gmail.com> ha scritto nel messaggio
news:g16g3j$2ak$2@aioe.org...
Thanks again, though I have heard a little about "smart pointer", I should
search some tutorials to learn it.
Smart pointers can give a productivity boost in C++ development, giving to
C++ programmers a kind of "managed heap" or "garbage collector" like C# and
..NET.
Actually, some smart pointer classes (like shared_ptr) are better than .NET
garbage collector, because garbage collector is non-deterministic, and is
good for memory resources only (garbage collector is not good for non-memory
resources, like textures, sockets, file handles... you must implement the
"dispose" pattern for them in C#...).
Instead, shared_ptr is deterministic (i.e. in the point in time that the
reference count of the pointed object becomes 0, the object is immediately
destructed, and its resource released), and shared_ptr is good also for
non-memory resources.
There's a video on Channel 9 about shared_ptr, by a bright member of VC++
Team: Stephan 'STL':
http://channel9.msdn.com/showpost.aspx?postid=385821
And there are some posts about that on VC++ Team's blog:
http://blogs.msdn.com/vcblog/archive/2008/02/25/channel-9-stephan-t-lavavej-digging-into-c-technical-report-1-tr1.aspx
http://blogs.msdn.com/vcblog/archive/2008/01/08/q-a-on-our-tr1-implementation.aspx
http://blogs.msdn.com/vcblog/archive/2007/12/26/just-what-is-this-tr1-thing.aspx
A final note:
If you use shared_ptr and smart pointers, your class instances must be
created on the heap (using 'new'), and not on the stack, as correctly David
W. pointed out.
HTH,
Giovanni