Originally Posted by
iMalc
What's more, how are you supposed to implement your own resource handling classes. E.g. to write a smart pointer you must use a smart pointer? Are other resources such as handles not just as important, if not more so, to prevent from being leaked? What's his policy on other types of resources?
the general rule here is to prefer the stack over the heap. i actually like this idea because usually the stack with allow us to do everything faster and more efficient than a heap (and has the added advantage we don't need to worry about leaking memory....at least i think the stack is safe for memory). and then in the case where we need something in the heap, we use a smart pointer.
as for resource clean up we have a smart handle class, something like this:
Code:
class SmartHandle {
HANDLE h;
~SmartHandle() { ::CloseHandle(h); }
};
it's got copy/assignment operators assigned so u can just do:
SmartHandle h = ::CreateFile(...);
we let the stack unwinding take care of clean up...and if we need the handle longer, we use a smart pointer.
the general idea is pretty good and i like it. it's just problematic when i want 1 class to refer to another class. his answer to this dilemma was to use a singleton....on my SOAP client class... :'(