On 27/01/2012, at 9:08 AM, Yi Ding wrote:
>
>
> Strict RAII would be counterproductive in certain cases, I agree, but it's
> not a big deal to have an init function in a class and still let that class
> handle all of the allocated memory (and deallocate it when it goes out of
> scope)
No of course that's fine! But it isn't really RAII to use
ctors/dtors/assignment for
memory management: that's what they're designed for and do well.
The problem is managing non-memory resources: file handles, sockets, etc.
I use RAII in some cases, for example it's nice to go:
void f() {
mutex dummy;
blah();
}
and have the mutex released on exit, even if the exit is an exception being
thrown from blah.
Indeed, for ZMQ messages, I was complaining that zmq_msg_init has
the wrong interface and semantics because I want to use it as a default
constructor. And put zmq_msg_close in the destructor.
--
john skaller
[email protected]
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev