[MOAB-dev] Discussion on return type of MOAB routines
Jed Brown
jed at jedbrown.org
Fri Jan 24 11:12:28 CST 2014
"Tim Tautges (ANL)" <tautges at mcs.anl.gov> writes:
> As Jed suggested,
>> if you want to preserve all this context data, we could create an
>> ErrorCode which is a pointer to a real ErrorContext, containing a
>> message and other relevant info. If success, always return NULL, which
>> for most standard compilers should translate to 0 ? Else, look deeper
>> in to the ErrorContext object and print/discard needed info.
>
> But how is that different than passing back an object owning a string? Most string implementations will have the
> character part dynamically allocated too, so in practice it should be almost the same. But the timing information is
> very different. I wonder whether that's because the ErrorCode return is POD, which gets optimized differently than when
> a class is returned?
Presumably you're paying for the std::string copy constructor (copy by
value, involves new dynamic allocation) followed by the std::string
destructor for the original object. Replace it with a raw pointer and
it'll be fast. Note that you'll need a way to collect the data behind
the pointer so it doesn't leak if the caller discards it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/moab-dev/attachments/20140124/1a01f044/attachment.pgp>
More information about the moab-dev
mailing list