Thank you all for your input.
I know that this problem may be solved in Perl or PDL, but now I am interested in exploring how it can be solved with Inline::C. I need speed, and I need compact.
Next, I see no problem in casting a bytestring using pack from Perl as a way of allocating a block of memory to be used in C as long as the block size is sufficient. That way the block of memory will be under Perl's memory management and garbage collection.
As I understand, you can overrule the Perl type from C by type casting, so the pack bytestring does not have to be an array of pointers.
Now, what is the problem with The "built-in" C 2D array? I should say that is exactly what I want - a 2D table of numbers. However, I will try my own index calculations as suggested.
Here is the code mock-up again - this time in code tags :o).
sub perl_routine { $byte_string = pack "I*", (0) x ( $x_dimension x $y_dimension ); c_function( $byte_string, $x_dimension, $y_dimension ); } void c_function( char *byte_string, int x_dimension, y_dimension ) { int **table = ( int ** ) byte_string; int i, j; for ( i = 0; i < x_dimension, i++ ) { for ( j = 0; j < y_dimension, j++ ) { table[ i ][ j ]++; } } }
Martin
In reply to Re: Passing a bytestring from Perl to Inline::C as a 2d array
by Anonymous Monk
in thread Passing a bytestring from Perl to Inline::C as a 2d array
by maasha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |