[geos-devel] Assertions in CoordinateArraySequence

Mateusz Loskot mateusz at loskot.net
Sun Jun 25 23:44:01 EDT 2006


Charlie Savage wrote:
> CoordinateArraySequence has a number of assertions that check to see 
> if the requested index is out of bounds of the array.  If it is, then
> the assertion is thrown - at least in Debug mode.
> 
> I'd guess assertions are off in Release builds (haven't checked), so 
> a segmentation fault would occur.
> 
> Could this be changed to exceptions?  When playing around at the 
> command line with Ruby or Python, its not very nice to have your 
> application terminate because you specify an invalid index.

This is a bad idea!
Using exceptions and checking if passed index is in range by default
will decrease performance pretty much.
Better idea is to provide two accessors: safe and unsafe, just as at()
and operator[] member functions in std::vector.

> The reason I can see for not doing this is the extra overhead in 
> checking the bounds - is that the case?

Yes.

> If so, are there profiling results showing that it really is a big 
> deal?

IMO, no profiling is needed because this is well-known issue.
Consider, why C++ Standard Committee introduced std::vector members I
named above. Single if clause when called hundreds or thousands times
will introduce significant overhead for sure.
Exceptions are even worst, because RTTI comes to the game.

IMHO, the most reasonable solution is to follow C++ STL design and take
the same decisions to provide optimal performance with guaranteed degree
of safety. So, all GEOS collections should provide similar API, doubled,
save and unsafe at the same time like at() and operator[] in std::vector.

This is only my opinion

-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the geos-devel mailing list