jey has asked for the wisdom of the Perl Monks concerning the following question:
My question is simple: does anyone know of a better way to do that? Especially, how is it possible to avoid the copying part?double foo(aref) SV * aref INIT: int i, last_index; int *array; if ((!SvROK(aref)) || (SvTYPE(SvRV(aref)) != SVt_PVAV) || ((last_i +ndex = av_len((AV *)SvRV(aref))) < 0)) { XSRETURN_UNDEF; } array = (int*)calloc(last_index+1, sizeof(int) CODE: for(i=0;i<=last_index;i++) array[i] = SvIV(*av_fetch((AV *)SvRV(array), i, 0)); RETVAL = foo_in_c(array, last_index+1); OUTPUT: RETVAL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extending Perl with C: how to use an array reference?
by ikegami (Patriarch) on Apr 11, 2007 at 21:26 UTC | |
|
Re: Extending Perl with C: how to use an array reference?
by djp (Hermit) on Apr 12, 2007 at 04:35 UTC | |
|
Re: Extending Perl with C: how to use an array reference?
by renodino (Curate) on Apr 12, 2007 at 02:33 UTC | |
|
Re: Extending Perl with C: how to use an array reference?
by BrowserUk (Patriarch) on Apr 11, 2007 at 23:15 UTC | |
|
Re: Extending Perl with C: how to use an array reference?
by salva (Canon) on Apr 12, 2007 at 08:27 UTC | |
|
Re: Extending Perl with C: how to use an array reference?
by aufflick (Deacon) on Apr 12, 2007 at 06:03 UTC |