Re: how to organize several class and their instance in windows programming
"asm23" <firstname.lastname@example.org> ha scritto nel messaggio
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
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
There's a video on Channel 9 about shared_ptr, by a bright member of VC++
Team: Stephan 'STL':
And there are some posts about that on VC++ Team's blog:
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.