Hey, So I was able to write an opcode using the following syntax, dynamically creating a new array. kArr1[] init 5 kArr2[] init 5 kNewArray[] add kArr1, kArr2 The new array structure is created but the arrayMemberSize, sizes, data and dimension members are 0 or NULL. I used a csound->Calloc to create the array->sizes array and the array->data array. Then I used a csound->RegisterDeinitCallback to call a csound->Free on these two arrays. I also filled in the arrayMemberSize and dimensions members. It all seems to be working ok. I was able to pass the newly created array to a different opcode and it worked as expected. As far as I can see there are two cases for dynamically allocating new array variables, creating arrays that are copies of the input arguments in the case of addition, subtraction, element wise multiplication etc. Then there are cases for creating specifically sized arrays. In the case of matrix multiplication, diskin style opcodes and numerous other cases I'm sure. So you could have a function like array copy: void array_copy(ARRAYDAT *source, ARRAYDAT *destination); Actually copy may not be the best name for that as you would really just be duplicating the dimensions and sizes of the array but i'm sure a better name could be chosen. And a straight up array allocation like maybe: void array_alloc(ARRAYDAT *array, int dimensions, int arrayMemberSize, int *sizes); Cheers, Ed On Friday 19 July 2013 at 23:03, Steven Yi wrote: > Hi Ed, > > Having reusable array utility functions sounds handy. Maybe it's > worth prototyping API functions here on the list? > > As for the dimensions, yeah, that's what my other email from a few > days ago was all about. I think right now the semantic analyzer > allows for any dimension array to match against an array arg > specifier. My proposal was to make k[] only match one dimension > k-arrays, and k[][] to only match against two-dimension k-arrays, etc. > No one has really replied to that other email and I've been > pre-occupied with other work; I'll probably go and implement the > proposal once I'm finished with the other work. > > Thanks! > steven > > On Fri, Jul 19, 2013 at 8:07 AM, Edward Costello > wrote: > > Thanks Steven, > > > > Yeah on closer inspection I noticed those functions were static, so yeah > > I'll have a look and just emulate what is being done in those functions. > > So am I right in thinking that generally, as it is supported now, all arrays > > need to be initialised using the init opcode before usage? It would be nice > > to have an array initialiser built in to the api, for things like writing > > opcodes like diskin opening samples to an array output, without having to > > query how many samples are in the file etc. or things like matrix to matrix > > multiplication where an output with the correct dimensions is automatically > > generated. > > Another thing I am confused about is the opcode arguments for array opcodes, > > does "k[]" mean a one dimensional argument and "k[][]" mean a 2 dimensional? > > You can use a one dimensional array on an argument that takes a "k[][]" and > > vice-versa and no error is reported. > > > > > > -- > > Edward Costello > > > > On Thursday 18 July 2013 at 18:45, Steven Yi wrote: > > > > Hi Ed, > > > > I think the ARRAYDAT should already be created by the compiler by the > > time you see it in your opcode. However, it's dimensions and data may > > not be initialized, which you may need to then modify yourself. I'm > > not sure about needing a deinit callback. I don't know what the > > standard practice is for freeing up memory for variables; perhaps we > > need to add a var_free function to CS_TYPE to automatically handle > > that... > > > > Otherwise, I'd look at Opcodes/arrays.c and use the functions John > > wrote as a model. > > > > Good luck! > > steven > > > > On Wed, Jul 17, 2013 at 10:06 AM, Edward Costello > > wrote: > > > > Hi, > > > > When creating a custom array opcode, for instance one that takes 2 arrays as > > input and give 1 array as output, in the initialisation function for the > > opcode, when creating the output array does one create an ARRAYINIT struct > > and pass that to the array_init function? Conversely is there a need to call > > the array_del function from a RegisterDeinitCallback? > > Thanks > > > > -- > > Edward Costello > > > > > > ------------------------------------------------------------------------------ > > See everything from the browser to the database with AppDynamics > > Get end-to-end visibility with application monitoring from AppDynamics > > Isolate bottlenecks and diagnose root cause in seconds. > > Start your free trial of AppDynamics Pro today! > > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > > _______________________________________________ > > Csound-devel mailing list > > Csound-devel@lists.sourceforge.net (mailto:Csound-devel@lists.sourceforge.net) > > https://lists.sourceforge.net/lists/listinfo/csound-devel > > > > > > ------------------------------------------------------------------------------ > > See everything from the browser to the database with AppDynamics > > Get end-to-end visibility with application monitoring from AppDynamics > > Isolate bottlenecks and diagnose root cause in seconds. > > Start your free trial of AppDynamics Pro today! > > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > > _______________________________________________ > > Csound-devel mailing list > > Csound-devel@lists.sourceforge.net (mailto:Csound-devel@lists.sourceforge.net) > > https://lists.sourceforge.net/lists/listinfo/csound-devel > > > > > > > > ------------------------------------------------------------------------------ > > See everything from the browser to the database with AppDynamics > > Get end-to-end visibility with application monitoring from AppDynamics > > Isolate bottlenecks and diagnose root cause in seconds. > > Start your free trial of AppDynamics Pro today! > > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > > _______________________________________________ > > Csound-devel mailing list > > Csound-devel@lists.sourceforge.net (mailto:Csound-devel@lists.sourceforge.net) > > https://lists.sourceforge.net/lists/listinfo/csound-devel > > > > > ------------------------------------------------------------------------------ > See everything from the browser to the database with AppDynamics > Get end-to-end visibility with application monitoring from AppDynamics > Isolate bottlenecks and diagnose root cause in seconds. > Start your free trial of AppDynamics Pro today! > http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net (mailto:Csound-devel@lists.sourceforge.net) > https://lists.sourceforge.net/lists/listinfo/csound-devel > >