[Bf-python] Vector data type

Campbell Barton cbarton at metavr.com
Mon Sep 25 16:16:00 CEST 2006


Martin Poirier wrote:
> --- Campbell Barton <cbarton at metavr.com> wrote:
>
>   
>> I was just looking and some areas for improvement.
>> and found the vector pytype,
>>
>> typedef struct {
>>     PyObject_VAR_HEAD
>>     struct{
>>         float *py_data;        //python managed
>>         float *blend_data;    //blender managed
>>     }data;
>>     float *vec;                //1D array of data
>> (alias)
>>     int size;
>>     int wrapped;            //is wrapped data?
>>     PyObject *coerced_object;
>> } VectorObject;
>>
>>
>> Looks like  theres 3 areas for  improvement.
>> *vec; points to either *py_data; and *blend_data; 
>> depending on  the 
>> wrapped; state.
>> why not just remove  *py_data; and  *blend_data; and
>> use vec only??
>>
>>     int size;
>>     int wrapped;            //is wrapped data?
>>
>> Could both be shorts? -would save 32bits, seems
>> overkill again, 64 bits 
>> of data- for what is a total of 6 possible states.
>>
>> *coerced_object;
>>
>> - We could have vector math with floats and matrices
>> without this.
>>
>> Anyone object to an attempt to optimize  this struct
>> for size?
>>     
>
> I would object to any modifications that would
> decrease the speed of vector manipulation operations.
> So be sure to check that too. And be sure that you're
> really reducing memory footprint, not just theorically
> doing so.
>
> Martin
>   

Agree, though I think it may not be as simple as this.
some of those variables arnt used very often in the C code and the 
advantage in making the pyObject use less memory could outweigh, the 
speed difference between  int/char operations.
I suspect it will make such a small impact either way that the less 
memory usage will be a better option.

the change I made to meshes faces and edges (iter is an char instead of 
an int) can be replaced with a separate pytype (kh_python, any comments?)
failing that  it can be tested or rolled back.

All talk and no action for the moment, but Ill try and find some time to 
look at testing possible improvements soon.

- Cam



More information about the Bf-python mailing list