in reply to readonly access to C-level strings

Any string available to Perl will have been copied into a Perl structure. You can free the C structure all you like. I don't think you'll succeed in making it read-only, but it certainly won't affect the string the C code points to.

-Paul

Replies are listed 'Best First'.
Re^2: readonly access to C-level strings
by tfoertsch (Beadle) on Jul 02, 2009 at 12:33 UTC
    What I want to avoid is exactly this copying. The strings are located in a mem segment that is mmapped read-only. So, there is no way for them to be changed and hence no need to be copied.

      hence no need to be copied.

      No, there is a need: For Perl to see them.

      The buffers of Perl strings are subject to modification and freeing at any time. It *might* be possible to tell Perl the PV associated with a scalar can't be changed, but

      • there's no way to tell Perl to use a existing memory block for the string buffer of a string, and
      • there's no way to tell Perl the string buffer of a string can't be freed.