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);
In reply to Re^2: Perl XS: garbage-collecting my malloc'd buffer (perlish?)
in thread Perl XS: garbage-collecting my malloc'd buffer by edan