pack "I*", (0) x ( $x_dimension x $y_dimension );
int **table = ( int ** ) byte_string;
table[ i ][ j ]++;
That still won't work and cannot be made to work! You will still get segfaults.
You cannot cast a 1D array point to a 2D array of arrays pointer. Full stop.
The memory for a 1D array (as produced by pack) is laid out so:
----------------------------....--------------------- ...|int1|int2|int3|int4|int4|....|N-3 |N-2 |N-1 |N | ----------------------------....---------------------
For a 2D array like so:
---- ptr | This is the int** ---- ... it points to an array of pointer below ... with one pointer for each of the first dimension --------------------------------------- ptr0|ptr1|ptr2|ptr3|....|Y-2 |Y-1 |Y | Each if these is an int * --------------------------------------- ... And each of those pointer point to contingous 1D arrays of ints ... each the size of the second dimension ... that can (and usually are) distributed at disparate position in me +mory ... and in no particular positions, even before the above block of ram +. --------....-----.....-----...etc |ary4| |ary2| |ary0| --------....-----.....-----...etc
There is simply no way to cast from one to the other.
In reply to Re^2: Passing a bytestring from Perl to Inline::C as a 2d array
by BrowserUk
in thread Passing a bytestring from Perl to Inline::C as a 2d array
by maasha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |