|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
> mjd-perl-pm@plover.com writes:
> [...]
> >
> > So for example the string "BLARF" probably takes about 30 bytes. (24
> > overhead plus 6 for "BLARF\0")
>
> Perl uses null-terminated strings internally? How odd.
It doesn't require the null-termination. It's for easier
compatibility with C extensions. Perl itself uses counted-length
strings, and stores the string's length (not including the extra
null).
> How, then, is a string with embedded NUL characters represented?
"blarf" is stored as
length 5
"barf\0"
"I\0like\0pie" is stored as
length 10
"I\0like\0pie\0"
Perl only pays attention to the length count, never to the null.
here's what the manual says about it:
All SVs that contain strings should be terminated with a NUL
character. If it is not NUL-terminated there is a risk of core
dumps and corruptions from code which passes the string to C
functions or system calls which expect a NUL-terminated string.
Perl's own functions typically add a trailing NUL for this
reason. Nevertheless, you should be very careful when you pass
a string stored in an SV to a C function or system call.
(perlguts)
Hope this helps.
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|