Can I pass an array of structs from object to object? Say I want to pass an array of t_custom which has four integers in the structure. Do I have to extract each integer from the structure and pass it as an array of A_LONGs? Or is there a way to pass the array of structs directly? Thanks
If you’re passing data between objects you’ve written yourself, you can just pass a pointer to the struct. Pointers generally look like longs.
Thanks for your answer Peter.
For some reason max crashes every time I try to do this. This is the code:
In sending object:
` t_atom av;
atom_setlong(av,(long)((x->MNLength)/2)); //length of the array, 100% correct one
atom_setlong(av+1, (long)(x->rMN_outData)); //pointer to an array of structs
post("outadress = %d, length %d",x->rMN_outData,(x->MNLength)/2);
outlet_anything(x->outlet_4, gensym("IBnote"), 2, av);`
In receiving object:
int numOfNotes = atom_getlong(argv); //getting the length post("inadress = %d, length %d",atom_getlong(argv+1),numOfNotes); //address and length same as the one sent sysmem_copyptr((t_Note*)atom_getlong(argv+1), x->ITHN_outData, numOfNotes*sizeof(t_Note));// crashing here
Is there anything I am doing wrong? The code worked before, when I passed the array using a conventional method, by setting each element of the struct as t_atom and passing an array of atoms. I thought I will try this method as it avoids the need of converting to and from t_Note struct but for some reason it crashes.
Ah, found it, I have to initialise x->ITHN_outData first.
C74 RSS Feed | © Copyright Cycling '74