[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] vector type: mutable or immutable



I'm for immutable. I used numpy arrays as vectors for a while but had
all kinds of bugs. I can't think of any use case for mutable vectors.

In reference to sharing a mutable vector to syncronize objects, there
are much better ways to do that. What happens if each object's update
method changes pos? It just doesn't make sense.

Also, for naming it would might be better to just have one object that
can be multiple sizes.

I attached a vector class that works like this pretty well.

On Mon, May 4, 2009 at 7:27 PM, René Dudfield <renesd@xxxxxxxxx> wrote:
> On Tue, May 5, 2009 at 4:17 AM, Casey Duncan <casey@xxxxxxxxxxx> wrote:
>>
>> Just to clarify my position, performance is a secondary concern, primarily
>> I'm concerned about intuitiveness and convenience. I suspect an immutable
>> vector type will cause a regular amount of mail traffic asking how to mutate
>> them and why that is not possible. I could be wrong, but I think many folks
>> will be surprised by an immutable vector class.
>>
>> I'm +0 on immutable vectors, they're certainly much better than nothing,
>> but I personally would prefer mutable.
>>
>> To make immutable types more performant, you should look at the
>> implementation of tuples in Python. tuple instances are pooled so they can
>> be recycled, saving a lot of memory management overhead. I did a similar
>> thing for vectors in Lepton with good results.
>>
>> -Casey
>
> +1 for memory pools.   Memory is the main overhead for performance these
> days.  Anything to avoid a copy or a malloc/mmap, and to group areas of
> memory together for reading.
>
> Mutable vectors fail the use cases:
> - use Vector as a proxy for some values in a larger array.
>         eg, in numpy I can do    reference_to_big_array = bigarray[1:3]
> - consistency with Rect, list, numpy/Numeric arrays, python arrays.
>
>
> Another use case is consistency with most other Vector types in CS.  I think
> most Vectors are mutable.
>     - allow people to use vectors like how they are used in most graphics
> literature.
>
>
> cu,
>

Attachment: vector.py
Description: Binary data