Code: Select all
type cool
dim abc() as string
end type
Code: Select all
type cool
dim abc() as string
end type
Code: Select all
#Define strWidth 255
Dim StringArray() As ZString * strWidth
Type DynamicType
StringArry As zString Ptr 'Arraypointer
End Type
Dim DT As DynamicType
ReDim StringArray(5)
StringArray(0)="Hello"
StringArray(1)="There!"
StringArray(2)="This is"
StringArray(3)="a HACK!"
DT.StringArry = @StringArray(0)
Print DT.StringArry[0*strWidth]
Print DT.StringArry[1*strWidth]
Print DT.StringArry[2*strWidth]
Print DT.StringArry[3*strWidth]
Sleep
Code: Select all
DT.StringArry = @StringArray(0)
Code: Select all
Type myString
Public:
Declare Constructor ()
Declare Destructor ()
Declare Operator Cast () As String
Declare Operator Let (newval As String)
Private:
As uByte Ptr _str_data
As uInteger _str_len
As Any Ptr _mutex
As Byte _valid
End Type
Constructor myString ()
this._mutex = MutexCreate()
MutexLock(this._mutex)
this._str_data = Allocate(1)
this._str_len = 0
this._valid = -1
MutexUnlock(this._mutex)
End Constructor
Destructor myString ()
DeAllocate(this._str_data)
this._str_len = 0
this._valid = 0
MutexDestroy(this._mutex)
End Destructor
Operator myString.Cast () As String
Dim tmpStr As String
If this._valid = 0 Then Return ""
If this._str_len = 0 Then Return ""
For i As Integer = 0 to this._str_len-1
tmpStr = tmpStr + Chr(this._str_data[i])
Next i
Return tmpStr
End Operator
Operator myString.Let (newval As String)
If Len(newval) = 0 Then
this._str_len = 0
Exit Operator
Else
MutexLock(this._mutex)
this._str_len = Len(newval)
this._str_data = ReAllocate(this._str_data, this._str_len)
For i As Integer = 0 To Len(newval)-1
this._str_data[i] = newval[i]
Next i
MutexUnlock(this._mutex)
End If
End Operator
Code: Select all
Dim myStr As myString
myStr = "Hi!"
Print myStr
Sleep
There's no problem with that. The actual string data isn't stored in the array. The array just holds the string descriptors - a descriptor, being a small, fixe-size structure that contains the length of the string, and a pointer to the actual data. This information is automatically updated whenever you change the string. It works just the same as when you're using a normal array, or even just a single string variable.notthecheatr wrote:I would also wonder if it's safe to assume you can even do that, since I would expect the strings themselves to move around every time you modify them (if they get larger, that is).
Code: Select all
Redim StringArray(5)
DT.StringArry = @StringArray(0)
Oh, OK. But it would be much nicer to put it in an OOP interface so we don't always have to update the pointer.counting_pine wrote:There's no problem with that. The actual string data isn't stored in the array. The array just holds the string descriptors - a descriptor, being a small, fixe-size structure that contains the length of the string, and a pointer to the actual data. This information is automatically updated whenever you change the string. It works just the same as when you're using a normal array, or even just a single string variable.