[…]
So, just copy the values instead! It’s simpler, faster and safer.
There’s no difference between my approach and passing a pointer to an
array of points regarding memory access; both will have to read two
values from an offset to the beginning of the structure for each point.
Right. I think I misunderstood your example the first time around. What you’re
actually doing is pass two pointers to “item 0”, and a stride for indexing?
The overhead of the stride calculations (two adds per point) would impact
either the caller or the callie anyway, so there’s not really a way to avoid
that in the general case anyway.
And not having to copy values around is faster than having to.
Sure, but I was still thinking “array of pointers”, which is a different
matter.
But you’re right, things should be simpler and safer, and having the
user use the same data type as used internally by the function kind of
defeats the purpose.
Yes… And as always, one has to consider the 70/30 (or 90/10 or whatever)
rule, and consider how much overhead there is in relation to actual work
performed. Function calls, potentially chaining through multiple API layers,
are very expensive when we’re dealing with single pixel operations and the
like, and compared to that, any of the proposed “npoints” approaches would be
a massive improvement.
Maybe having it implemented with ints for the coordinates and a simpler,
safer function which takes SDL_Points and passes it to the other? I
think ints would cover most other libraries and you get the speed
benefit of not copying values around.
Not sure… I kind of prefer APIs that provide one single interface that is as
simple, clean, safe and flexible as possible. Alternative interfaces have to
be really nice and useful to be motivated, because they are add to the size of
the API that you have to learn and understand.
That said, sometimes one has to make exceptions to avoid substantial
performance issues, and I’d say the npoints deal (as opposed to one API call
per line) isi n that category.
I’m not so sure the way you pass the actual coordinates matter enough that one
can defend providing multiple variants. Maybe it does for pixels on software
surfaces, but lines over OpenGL or Direct3D…?On Wednesday 09 December 2009, at 00.00.29, Andre de Leiradella wrote:
–
//David Olofson - Developer, Artist, Open Source Advocate
.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’