I wonder why code 1 compiled normally while code 2 not:
Code1:
Code: Select all
dim s as string = environ("PATH")
dim z as ZString ptr = strptr(s)
Code: Select all
dim z as ZString ptr = strptr(environ("PATH"))
Thank you.
Code: Select all
dim s as string = environ("PATH")
dim z as ZString ptr = strptr(s)
Code: Select all
dim z as ZString ptr = strptr(environ("PATH"))
Code: Select all
dim as zstring ptr psz = CAllocate(1024, 1) ' allocate memory
*psz = Environ("path") ' dereference the ptr (store string data)
Print *psz ' show it
Sleep
' clean up: free alloc'ed memory
DeAllocate(psz)
Code: Select all
'Using a static String
Dim As String s
s = Environ("path")
Print s
Print
'Using a static ZString pre-sized
Dim As ZString * 1024 z
z = Environ("path")
Print z
Print
'Using a dynamic String
Dim As String Ptr ps = New String
*ps = Environ("path")
Print *ps
Print
Delete ps
'Using a dynamic ZString pre-sized (as proposed by MrSwiss)
Dim As ZString Ptr pz = CAllocate(1024, Sizeof(UByte))
*pz = Environ("path")
Print *pz
Print
DeAllocate(pz)
Sleep
(1) is handled by the Compiler (internally), you don't have "to do" anything, but:As I understand, memory must be allocated 2 times: (1) when then temp variable is created; (2) create another string to copy that variable to ?