Forums > Dev

### General question about operations on list of numbers

Nov 29 2012 | 1:06 pm

Hello,

I want to get a list of numbers into my object and perform some operations on these numbers.

Each operation will create new values.

I am seeking a general advice: would you store each lists as an atom, convert the data to longs of doubles only for the calculations and then store the data back into atoms after each operation or would you rather convert the incoming data into regular C arrays, perform all the calculations and put the data into an atom only when you send them to the output ?

Nov 29 2012 | 7:49 pm

Hello Nicolas,

This is how I am doing it. Currently I am putting data into an array of long integers and then I put the outcome list in an atom just before sending it to output. What do you think about it ?

Another source for… …sources – especially when it comes to lists – are Peter Elsea’s lobjects. But I don’t understand everything. Pointers and friends are still giving me headaches. Aargl.

``````void rb_mebiii_list(t_rb_mebiii *x, t_symbol *s, short ac, t_atom *av)
{
short performable ;

if (ac >= 6) {																				// performs if list has six items at least
short i;

for (i=0 ; i < 6; i++) {
postatom(&av[i]);
if (atom_gettype(av)==A_LONG) {														// checks type (expected : long)

// fills array of coordinates with values from list
x->pointsRoughCoords[i] = atom_getlong(av);
if (x->pointsRoughCoords[i] >= 0 && x->pointsRoughCoords[i] < = 1023) {	// checks value (expected : 0... ...1023)
performable = 1;
}
else {
performable = 0;
}
}
else {
post("rb.mebiii: element at position %i is not an integer !", i+1);
performable = 0;
break;
}
}

if (performable == 1) {
t_atom myList[3];
filterPoints(x);
averagePoints(x);
calculateDistances(x);
sortDistancesAndGetRoughZ(x);
calibrateZ(x);
x->output_list[0] = x->xPosition;
x->output_list[1] = x->yPosition;
x->output_list[2] = x->calibratedZPosition;

for (i=0; i < 3; i++) {							// transferts data into t_atom
atom_setfloat(myList+i,x->output_list[i]);
}
outlet_list(x->outlet1,0L,3,myList);
}
else {
post("rb.mebiii: wrong data - cannot operate !");
}

}
else {
post("rb.mebiii: a list with %i elements is too short", ac);
}
}``````
Nov 30 2012 | 8:02 am

Thanks a lot for your help, Nicolas.

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

Forums > Dev