[gdal-dev] create 25D MultiPolygon how to

legeochen legeochen at gmail.com
Sat Mar 28 21:33:54 EDT 2009


Mateusz Loskot
Thanks!! I'll keep this in mind. It's really important to good performance.

2009/3/29 Joaquim Luis <jluis at ualg.pt>

> Thankx
>
> I'll keep this in mind if I ever one day start practicing C++
> For the time being, only good old C.
>
> Joaquim
>
>  Joaquim Luis wrote:
>>
>>> Mateusz Loskot wrote:
>>>
>>>   for(Roadway::RoadWayArray::iterator itrw = _roadwayArr.begin(); itrw !=
>>>>> _roadwayArr.end();itrw++)
>>>>>
>>>> ++itrw;
>>>>
>>>> if you care about performance.
>>>>
>>> Mateusz,
>>>
>>> Just curious. Why should that impact on performance?
>>>
>>
>> The itrw here is most likely an iterator of type of user's class.
>> The pointer arithmetic does work here only in terms of
>> semantic, but not in terms of implementation.
>> Meaning, both versions do the same - advance to next position:
>>
>> int* p = ...; // or any ordinary type
>> p++;
>>
>> iterator it = ...;
>> it++;
>>
>> However, the realization is completely different.
>> Here is example of how pre- and post-increment operator is usually
>> declared in a class:
>>
>> struct T
>> {
>>   T& operator++(); // pre-
>>   T operator++(int); // post-
>> };
>>
>> The pre-increment operator returns reference to the object
>> itself (return *this;)
>>
>> The post-increment returns a temporary copy of the object.
>> There are important side-effects of returning copy:
>> 1. it is constructed -> copy-construction -> constructor called
>> 2. it is returned by value -> copy-construction -> constructor called
>>
>> Here is example of iterator and operator++ implementation:
>> http://liblas.org/browser/trunk/include/liblas/iterator.hpp?rev813#L108
>>
>> Object construction is considered in C++ as an expansive operation,
>> next to dynamic storage allocation.
>> If post-increment/decrement operator is used against pointers and
>> integers, temporary object is also created, but as they are native
>> types no constructor call is involved.
>>
>> People report different measurements on Usenet groups. Numbers
>> vary but can easily hit 50 % of performance increase if you
>> stick to use of pre-increment/decrement operator for class types.
>>
>> Best regards,
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090329/e6651c0e/attachment.html


More information about the gdal-dev mailing list