in reply to Passing a very large string by reference to a c library
You see, the c uses pointers to address the strings. Char is the default type, you need to convert inside the code.SV * _smooth2( yp, wp, lambda_in, m ) char * yp char * wp SV * lambda_in int m CODE: { int i, i1, i2, ip; double c[MMAX+1], d[MMAX+1], e[MMAX+1], w[MMAX+1], y[MMAX+1], z[MMAX+1], lambda; double * ya; double * wa; ya = (double *) yp; wa = (double *) wp;
From perl, I call:
Where the $py and $pw are strings. XS automagically builds the pointers for you.Smooth::_smooth2( $py, $pw, $lambda, scalar( @$yref ) );
Hope this helps,
Jeroen
"We are not alone"(FZ)
Update: Because the c-code sees only the pointers,
no copy is made. To be sure, I tested it with a fresh module:
TestMemXS:
The perl process didn't exceed 55M...#XS #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "unistd.h" MODULE = TestMemXS PACKAGE = TestMemXS void _test( yp ) char * yp CODE: { double * ya; ya = (double *) yp; sleep( 1000 ); } ------------------- #testMemXS.pm .... sub testMem{ my $str = "\000" x 50e6; _test( $str ); } .... ------------------- perl -MTestMemXS -e 'testMem()'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Passing a very large string by reference to a c library
by dino (Sexton) on Jul 16, 2001 at 15:22 UTC | |
|
Re: Re: Passing a very large string by reference to a c library
by dino (Sexton) on Jul 12, 2001 at 17:02 UTC | |
by tye (Sage) on Jul 13, 2001 at 20:56 UTC |