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;
You see, the c uses pointers to address the strings. Char is
the default type, you need to convert inside the code.
From perl, I call:
Smooth::_smooth2( $py, $pw, $lambda, scalar( @$yref ) );
Where the $py and $pw are strings. XS automagically builds
the pointers for you.
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:
#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()'
The perl process didn't exceed 55M... |