in reply to Re: Perl XS: garbage-collecting my malloc'd buffer
in thread Perl XS: garbage-collecting my malloc'd buffer
I'd think that ($len,$buf)= my_xs_func(...) would often be inconvenient and thus not very "perlish" (Perl places a large value on programmer convenience) and I consider the interface provided by Perl's own read and related functions to be "perlish". So I'd go with the original design.
You should also note that your code assumes that the buffer gets populated with a '\0'-terminated string. [ Update: as does the original node's second code block, so that is probably a safe assumption (: ]
If I was sure that the values being created were very unlikely to be very large and that they didn't contain internal pointers, then I might go with copying the generated value but only if the integer returned by the function was just the length so I could use:
Mileage will certainly vary. - tyemy $result= my_xs_funct($struct,$len); my $outlen= length($result);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^2: Perl XS: garbage-collecting my malloc'd buffer (perlish?)
by Elian (Parson) on Mar 03, 2003 at 17:44 UTC | |
by tye (Sage) on Mar 03, 2003 at 18:03 UTC | |
by Elian (Parson) on Mar 03, 2003 at 18:20 UTC | |
by tye (Sage) on Mar 03, 2003 at 19:09 UTC |