Home  |  Linux  | Mysql  | PHP  | XML
From:Paulo Filipe Andrade Date:Thu Jul 31 04:30:27 2008
Subject:Re: Allocating a char* and returning to Perl from a C function
Tanks guys, got it working.

SV *work(char *str){
	char *ret, *ncp;
	SV *perlRet;
	
	ret = New(0, ret, retLen, char);
	ncp = ret;
	while(*cp){
		// work with ncp and cp
		*cp++;
	}
	*ncp = "\0";
	perlRet = newSVpvn(ret, strlen(ret));
	Safefree(ret);
	return perlRet
}

This is currently working :).
However, an optimization could be done if I could avoid copying the  
string I'm working on before returning it.
The strings passed in can be rather large, and this would be nice to  
avoid allocating so much space.

I was thinking of something in the line of creating an SV of type pv  
right away, and then using sv_2pvbyte_nolen to get the buffer.
I think this should work, but I can't find a newSVpv function that  
allows me to specify the string length I want without passing in a  
char *.

Any other suggestions?

BTW, the code also works with malloc / free :)

Paulo F. Andrade
pauloandrade@ist.utl.pt




Navigate in group perl.inline at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants