[MOAB-dev] Discussion on return type of MOAB routines

Wu, Danqing wuda at mcs.anl.gov
Wed Jan 22 10:33:12 CST 2014


Our concern is more on "Return traditional enum type ErrorCode" VS "Return a class object with more information". 

The class contains a string type error message in addition to an ErrorCode. Returning a class type always has more overhead than ErrorCode, with some benchmark tests.

What is your preference? Do you know why PETSc still uses ErrorCode style? For now, the reason that we might need to return a class containing error message is to support some non-error conditions (like tag not found)
________________________________________
From: Jed Brown [jed at jedbrown.org]
Sent: Wednesday, January 22, 2014 10:16 AM
To: Wu, Danqing; Tautges, Timothy J.; Vijay S. Mahadevan
Cc: moab-dev at mcs.anl.gov
Subject: RE: [MOAB-dev] Discussion on return type of MOAB routines

"Wu, Danqing" <wuda at mcs.anl.gov> writes:

> The object contains an enum type ErrorCode and std::string. The size
> of this object is fixed, like 16 bytes in my test. However,
> std::string is essential like a wrapped pointer implemented by
> STL.

Yes, do you really want your error handler to use dynamic memory allocation?

> Here I think the "size" Tim mentions is related to the length of the
> string, which will affect the performance of the copy constructor of
> std::string, when this object is returned by value from MOAB routines.

You could use a pointer so that there is no copy, but you have to
allocate the string somewhere.


More information about the moab-dev mailing list