2 ways to get an object's attribute


    Nov 19 2007 | 3:34 pm
    Dear list,
    I came across this piece of code in jit.gl.gridshape:
    long ac=0; t_atom *av=NULL;
    jit_object_method(x,gensym("getcolor"),&ac,&av); if ((ac==4)&&av) { color[0] = jit_atom_getfloat(av); color[1] = jit_atom_getfloat(av+1); color[2] = jit_atom_getfloat(av+2); color[3] = jit_atom_getfloat(av+3); jit_freebytes(av,ac*sizeof(t_atom)); }
    Is this somehow more efficient to get an objects attribute then doing something like the following?
    float color[4];
    jit_attr_getfloat_array(x, gensym("color"), 4, color);
    I think its obvious which one I'd prefer to use, but I'm just curious if there is a good reason to use the first method. Or is it just "old" jitter coding style?
    Thijs

    • Nov 19 2007 | 3:44 pm
      You would use the first method if you don't know the size of the array, but the 2nd method is a convenience version of the 1st for situations in which you do. They are equivalently efficient.
      jb
      Am 19.11.2007 um 16:34 schrieb Thijs Koerselman:
      > Dear list, > > I came across this piece of code in jit.gl.gridshape: > > long ac=0; > t_atom *av=NULL; > > jit_object_method(x,gensym("getcolor"),&ac,&av); > if ((ac==4)&&av) { > color[0] = jit_atom_getfloat(av); > color[1] = jit_atom_getfloat(av+1); > color[2] = jit_atom_getfloat(av+2); > color[3] = jit_atom_getfloat(av+3); > jit_freebytes(av,ac*sizeof(t_atom)); > } > > Is this somehow more efficient to get an objects attribute then > doing something like the following? > > float color[4]; > > jit_attr_getfloat_array(x, gensym("color"), 4, color); > > I think its obvious which one I'd prefer to use, but I'm just > curious if there is a good reason to use the first method. Or is it > just "old" jitter coding style? > > Thijs > > >
    • Nov 19 2007 | 3:47 pm
      On Nov 19, 2007 3:44 PM, Jeremy Bernstein wrote:
      > You would use the first method if you don't know the size of the > array, but the 2nd method is a convenience version of the 1st for > situations in which you do. They are equivalently efficient. > > Hi Jeremy,
      Thanks for letting me know. I didn't think about the variable array size.
      Best, Thijs