Dear All, 

I have an issue that I can't seem to see addressed fully, apologies in 
advance if this has already been posted. 
Here is the issue: 

given a C function that I compile with emcc:    

int allocatearray(float** array,int* parray_size){

array_size=rand(10); 
 float* array= (float*) malloc(array_size); 
*parray_size=array_size;
*parray=array; 
}


this function allocates an array for which I do not initially know the 
size, hence cannot be done on the 
js side, only the c side  knows how to handle the allocation. 

I would like to be able to create a js array that is allocated insize the 
"c" function allocatearray: 

i.e: I would like to write the following code: 

var allocated_array;
var allocated_array_size;  
AllocateArray = Module.cwrap('allocate_array','number',['number','number']);

but I don't seem to understand how using the module heap I could retrieve 
the allocated_array 
and its size, how would the call even look like? 
AllocateArray(&allocate_array, & allocated_array_size); ? //that's not 
javascript! but that's what I would like to write

I could try and build a pointer in the module heap, and pass that on to the 
AllocateArray module, but I need to pass 
a pointer to a pointer if I want to be able to allocate it. How do you 
create a NULL pointer in javascript, and get 
it allocated within the c function? 

I have seen a lot of documentation on how to pass a pointer from js to C, 
but here, it's different, I want to pass 
a NULL pointer from js to C, have C allocate it, and return it to js. 

I would appreciate any help on the issue, thanks a lot in advance!

Eric


-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to