c - Does the dart VM impose restrictions on the stack memory size of a native extension? -
i'm learning write native extension , noticed odd occurrence. when allocate multidimensional array , access so: (excuse messy c code , bad practices might using unless they're cause of error. c not-so-great)
int table[rows][cols]; //rows , cols both > 1 memset(table, 0, sizeof(int) * rows * cols);
i segmentation fault if like
table[rows-1][cols-1];
but if allocate table so:
table = (int**)malloc(xlen * sizeof(int *)); if (table == null) { ... error ... } (i=0; < xlen; i++) { table[i] = (int*)malloc(ylen * sizeof(int)); if (table[i] == null) { ... error ... } memset(table[i], 0, sizeof(int) * ylen); }
then works fine. why might be?
maybe problem in in first case allocate array on stack?
if use reference array outside of function (after when function returns) segmentation fault.
please give small example of use of array , you'll more useful advice.
Comments
Post a Comment