Forums > Dev

dimstride confusion

February 28, 2007 | 5:17 pm

I’m really confused about the calculation of dimstride. From what I know, in
a 2 dim matrix you calculate the first 2 dimstrides like this:

dimstride[0] = sizeof(type) * planecount
dimstride[1] = dimstride[0] * dim[0];

if I instantiate a matrix in a patch, and I check the dimstrides with
option-rightclick, the value of dimstride[1] seems to be rounded to the
highest multiple of 16 for small dimensions.

for example a "4 char 10 10" matrix has a dimstride of 4, 48 and size 480

but a "4 char 1000 10" matrix has a dimstride of 4, 4000 and size 4000

I’m creating new matrices in my externals that are shared with the jitter
patch/externals.Should I worry about this or can I just create a matrix_info
struct with dimstrides 4 40 and size 400?

cheers, -thijs


February 28, 2007 | 5:26 pm

Yes, dimstride[N>0] is padded to 16-byte values for faster vector
processing (e.g. Altivec).

You shouldn’t need to worry about dimstride most of the time — it’s
automatically calculated by Jitter when a matrix is created or resized.

jb

Am 28.02.2007 um 18:17 schrieb Thijs Koerselman:

> I’m really confused about the calculation of dimstride. From what I
> know, in a 2 dim matrix you calculate the first 2 dimstrides like
> this:
>
> dimstride[0] = sizeof(type) * planecount
> dimstride[1] = dimstride[0] * dim[0];
>
> if I instantiate a matrix in a patch, and I check the dimstrides
> with option-rightclick, the value of dimstride[1] seems to be
> rounded to the highest multiple of 16 for small dimensions.
>
> for example a "4 char 10 10" matrix has a dimstride of 4, 48 and
> size 480
>
> but a "4 char 1000 10" matrix has a dimstride of 4, 4000 and size 4000
>
> I’m creating new matrices in my externals that are shared with the
> jitter patch/externals.Should I worry about this or can I just
> create a matrix_info struct with dimstrides 4 40 and size 400?
>
>
> cheers, -thijs
>
>
>
>


February 28, 2007 | 5:28 pm

On 2/28/07, Thijs Koerselman

wrote:
> I’m really confused about the calculation of dimstride. From what I know, in
> a 2 dim matrix you calculate the first 2 dimstrides like this:
>
> dimstride[0] = sizeof(type) * planecount
> dimstride[1] = dimstride[0] * dim[0];
>

This is close but not quite correct. dimstride[0] will be the way you
wrote above, but dimstride[1] goes as follows

dimstride[1] = dimstride[0] * dim[0] + padding;

The padding is for byte alignment. Most 32bit processors prefer
memory that is 4-byte aligned. It’s nothing you need to worry about
in terms of how much memory your matrix takes up. You do need to pay
attention when iterationg over matrix cellse. Always do

rowstart = j*dimstride[1];

wes


February 28, 2007 | 7:10 pm

On 2/28/07, Wesley Smith wrote:
>
> On 2/28/07, Thijs Koerselman

wrote:
> > I’m really confused about the calculation of dimstride. From what I
> know, in
> > a 2 dim matrix you calculate the first 2 dimstrides like this:
> >
> > dimstride[0] = sizeof(type) * planecount
> > dimstride[1] = dimstride[0] * dim[0];
> >
>
> This is close but not quite correct. dimstride[0] will be the way you
> wrote above, but dimstride[1] goes as follows
>
> dimstride[1] = dimstride[0] * dim[0] + padding;
>
> The padding is for byte alignment. Most 32bit processors prefer
> memory that is 4-byte aligned. It’s nothing you need to worry about
> in terms of how much memory your matrix takes up. You do need to pay
> attention when iterationg over matrix cellse. Always do
>
> rowstart = j*dimstride[1];
>
>

Thanks for the quick replies! I guess I do need to worry about it, because
in my code I’m either creating new matrices or linking to existing ones, but
in either case I resize them from within my externals by setting a the info
struct and getting the new data pointer.

Somewhat related… If a matrix doesn’t exist yet, I create a new one and
set the name attribute in order to share it with later instances in my
patch. Like this:

t_atom atom;

// create new matrix
x->mx = jit_object_new(_jit_sym_jit_matrix, &(x->mx_info));

// set name
jit_atom_setsym(&atom, x->mx_name);
object_attr_setvalueof(x->mx, _jit_sym_name, 1, &atom);

If I then afterwards create a named matrix in my patch, it doesn’t seem to
share with this one. Am I missing something? I don’t know how to create a
"matrix myname" from C other than this.

best, -thijs


February 28, 2007 | 10:07 pm

Hi Thijs,
You need to register your matrix with a name and attach it as well to
receive notifications on changes. These functions are documented in
the Jitter API docs
(http://cycling74.com/download/JitterAPIReference/) under the object
module.

void * jit_object_register (void *x, t_symbol *s)
Registers an object in the named object registry.

void * jit_object_attach (t_symbol *s, void *x)
Attaches an object as a client of a named server object for notification.

wes


February 28, 2007 | 10:43 pm

If you are using jit_object_method(matrix, gensym("setinfo"), &info),
dimstride is set for you automatically. Truly.

jb

Am 28.02.2007 um 20:10 schrieb Thijs Koerselman:

> Thanks for the quick replies! I guess I do need to worry about it,
> because
> in my code I’m either creating new matrices or linking to existing
> ones, but
> in either case I resize them from within my externals by setting a
> the info
> struct and getting the new data pointer.


March 1, 2007 | 12:14 pm

On 2/28/07, Wesley Smith wrote:
>
> Hi Thijs,
> You need to register your matrix with a name and attach it as well to
> receive notifications on changes. These functions are documented in
> the Jitter API docs
> (http://cycling74.com/download/JitterAPIReference/) under the object
> module.
>
> void * jit_object_register (void *x, t_symbol *s)
> Registers an object in the named object registry.
>
> void * jit_object_attach (t_symbol *s, void *x)
> Attaches an object as a client of a named server object for
> notification.

Ah of course, forgot about that. Thanks. I’m using the notification thing
for my own use already.

-thijs


March 1, 2007 | 12:22 pm

On 2/28/07, Jeremy Bernstein wrote:
>
> If you are using jit_object_method(matrix, gensym("setinfo"), &info),
> dimstride is set for you automatically. Truly.

Thanks Jeremy, it’s good to know. Might be something to put this in the docs
(?) It’s a little confusing. You pass it the struct but certain members are
used and others are calculated. The jit api only states:

" Sets all attributes according to the t_jit_matrix_info struct provided."

but I’m glad I don’t have to deal with it after all :-)

best, -thijs


Viewing 8 posts - 1 through 8 (of 8 total)