----- Original Message ----- 
From: <[EMAIL PROTECTED]>
To: <perl-win32-users@listserv.ActiveState.com>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, November 14, 2006 9:53 AM
Subject: perl inline c and weird buggy-ness


>
> hi there perl gurus.
>
> I am creating a module in inline c. I want to concat a very large string
fast. I
> am getting weird crashes for each run. Also, it appears that my string is
not
> being concatinated at all.
>
> I am using VC6.0, perl 5.8 on win32 xp.
>
> how can I get this to work.
>
> your help is appreciated. Thanks.
>
> -Jer A.
>
> ---------------------------------------------------------------------
> #!Perl
>
> package DSTRING;
>
> my $code = <<'END_C';
>
>
> void concat( char *a, char *b, char *c) // got this function from a
website
> {
> while( *a )  {           /* while( *c++ = *a++ );  */
> *c = *a; ++a; ++c;
> }
> while( *b )  {
> *c = *b; ++b; ++c;
> }
> *c = '\0';
> }
>
>
> char* addString(char* DATA,char* dataToAdd) {
>    concat(DATA, strdup(dataToAdd),DATA);
>    return DATA;
> }
>
>
> END_C
>
> use Inline;
>
> Inline->bind(C => $code);
>
> 1;
>
> my $data = "";
>
> my $count = 0;
> for(1...100000)
> {
> print $count,"\n";
>
> $data = DSTRING::addString($data,"testdata");
> $count++;
> }
>
>
> print $data;
>
> print "END\n";
>

Possibly it's just the use of strdup() that's causing the problem. It (and a
few other functions) should be avoided in Inline::C/XS. See 'perldoc
perlclib'.

I didn't try to run your script .... it was simpler just to provide the
following (based on an example found in "Extending and Embedding Perl" by
Cozens and Jenness). The script I've written uses a different layout to the
one you used - though I don't think the layout you used had anything to do
with the problems you experienced.

---------------------------
package DSTRING;

use Inline C => Config =>
    BUILD_NOISY => 1; # see the compilation report

use Inline C => <<'END_C';

SV * addString (char * str1, char * str2){
   SV * outsv;
   outsv = newSVpv(str1, 0);
   sv_catpv(outsv, str2);
   return outsv;
}


END_C

my $data = "";

my $count = 0;
for(1...10) # keep it brief for the demo
{
print $count,"\n";

$data = DSTRING::addString($data,"testdata");
$count++;
}

print $data;

print "END\n";
-----------------------------

One problem here is that addString() creates a new SV at each iteration.
That could be worth avoiding if you're calling lots of iterations ... not
sure .... perhaps the overhead isn't that great in relation to the overall
time taken.
(I'll take a closer look later when I have more time.)

Cheers,
Rob

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to