[osg-submissions] Fixing osgTerrain::Layer::getFileName problemwith osgDotNet

Robert Osfield robert.osfield at gmail.com
Thu Sep 6 00:45:42 PDT 2007


HI Mike,

On 9/5/07, Mike Wittman <mwittman at seismicmicro.com> wrote:
> My understanding was that C++ standard library implementations commonly
> use reference counting and copy-on-write to internally manage
> std::string data.  In that case return-by-value should be relatively
> cheap.

I'm afraid this type of copy isn't cheap as the std::string internal
sharing of data requires the use of mutex, which is expensive, far far
more expensive than just passing around a point to the std::string as
is the case for a reference.

> Unfortunately, the difference in rules for const reference vs. non-const
> reference doesn't really help much in this case.  The problem occurs
> when C++ code invokes getFileName on a wrapper's C# subclass that has
> had getFileName overridden.  In that case it's necessary to convert a C#
> string to a C++ const std::string&, which is not possible without
> managing some semi-persistent std::string storage in the wrapper (and
> even then it doesn't have identical semantics).  Since the general
> solution for this is complex and a simple one-off solution isn't
> apparent, I'll just disable the getFileName functions in the wrappers.

Could you not just treat the const std::string& as a std::string on
the C# side?  Since it is const there is no mechanism for modifying
the original string.

Robert.


More information about the osg-submissions mailing list