std.stringbuffer

Me Here p9e883002 at sneakemail.com
Wed Apr 30 02:30:12 PDT 2008


As my ascii art was screwed by the time it got to the server, here is a 
better illustration of what goes on:
This is long and wordy and maybe of no interest. But it does illustrate 
the point i was trying to make.

[0] Perl> use Devel::Peek;;
[0] Perl> Dump $s;;              ### Uninitialised scalar -- no space 
allocated.
SV = NULL(0x0) at 0x194a9cc
   REFCNT = 1
   FLAGS = ()

[0] Perl> $s = 'abcdefghijklmnopqrstuvwxyz';;        ### Assign it a string
[0] Perl> Dump $s;;
SV = PV(0x2252e8) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,pPOK)
   PV = 0x191e1a4 "abcdefghijklmnopqrstuvwxyz"\0   ## the data
   CUR = 26                                                  ### user visible length
   LEN = 27                                                   ## +1 for null incase we pass it to C

[0] Perl> substr( $s, 0, 5 ) = '';;                           ### Remove 
teh first 5 characters
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,OOK,pPOK)
   IV = 5  (OFFSET)                                 ### offset of 5 fro the start of the buffer
   PV = 0x191e1a9 ( "abcde" . ) "fghijklmnopqrstuvwxyz"\0
### Still there but not visible
   CUR = 21                         ### User visible length
   LEN = 22                          ### Internal length (+ offset above)

[0] Perl> substr( $s, -10 ) = '';;   ##' chop of the last 10 chars
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,OOK,pPOK)
   IV = 5  (OFFSET)
   PV = 0x191e1a9 ( "abcde" . ) "fghijklmnop"\0
   CUR = 11                       ### User visible lentgh changes
   LEN = 22                        ### Internal length doesn't.

[0] Perl> $s = 'XX' . $s;;          Prepend some new stuff back
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,OOK,pPOK)
   IV = 5  (OFFSET)
   PV = 0x191e1a9 ( "abcde" . ) "XXfghijklmnop"\0
   CUR = 13                      ### User length grows
   LEN = 22                       ### internal length doesn't

[0] Perl> $s .= 'XX';;          ### Append some new chars
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,OOK,pPOK)
   IV = 5  (OFFSET)
   PV = 0x191e1a9 ( "abcde" . ) "XXfghijklmnopXX"\0
   CUR = 15                     ### Ditto the above
   LEN = 22

[0] Perl> $s .= '??????';;       ### Fill it to the limit of the not 
offset space
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,OOK,pPOK)
   IV = 5  (OFFSET)            ### Offset unchanged
   PV = 0x191e1a9 ( "abcde" . ) "XXfghijklmnopXX??????"\0
   CUR = 21
   LEN = 22

[0] Perl> $s .= '##';;         ### Push it beyond that limit
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,pPOK)
   IV = 0                       ### Offset reclaimed
   PV = 0x191e1a4 "XXfghijklmnopXX??????##"\0
   CUR = 23
   LEN = 27

[0] Perl> $s .= '###';;     Upto the original allocation
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,pPOK)
   IV = 0                 ### Still the same address (below)
   PV = 0x191e1a4 "XXfghijklmnopXX??????#####"\0
   CUR = 26
   LEN = 27

[0] Perl> $s .= '!';;    ### Push it beyond the original allocation
[0] Perl> Dump $s;;
SV = PVIV(0x2256ec) at 0x194a9cc
   REFCNT = 1
   FLAGS = (POK,pPOK)
   IV = 0          ### Reallocation occurs now
                    ### Though in place because nothing else has allocated memory.
   PV = 0x191e1a4 "XXfghijklmnopXX??????#####!"\0
   CUR = 27
   LEN = 28

-- 




More information about the Digitalmars-d mailing list