I see.
I had to remove the older version since I discovered that ByRef passed UDT-subsets seem not to work, so there are some new functions and also some new syntax to some existing functions. Now these functions await an address where to find/store the pointer - these functions names end with "At" now.
StrLen-Function still inside - attention that works only on String/String-Array but not on strings which are subsets of an UDT.
Also Set$ I changed to SetStr since it does not return a string. Same applies to SetUdtStr. Mainly the functions work still the same way as described above, a few have been exchanged:
Some demonstration code that shows usage of heap as dynamic UDT-subsets
Heap_SetAt
Heap_AppendAt
Uses "Console"
#INCLUDE "lazyFun.tBasicU"
Type t_type
S1 As DWord
S2 As DWord
End Type
Type t_Subtype
A As Long
B As Byte
C As Double
End Type
Dim foo(3) As t_type
Dim dummy As t_Subtype
Dim i As Long
For i = 1 To 3
' now tell foo(2).S1 to hold something:
dummy.A += 12
dummy.B += 3
dummy.C += 4.5
Heap_AppendAt(VarPtr(foo(2).S1), Memory_Get(VarPtr(dummy), SizeOf(t_Subtype)) )
Next i
' retrieve data:
Dim dArray(HEAP_Size(foo(2).S1)\SizeOf(t_SubType)) As t_SubType At foo(2).S1
For i = 1 To UBound(dArray)
' PrintL "element" + Str$(i)
PrintL "A:" + dArray(i).A
PrintL "B:" + dArray(i).B
PrintL "C:" + dArray(i).C
PrintL
Next
PrintL $CRLF + "key to continue" + $CRLF
WaitKey
dummy.A = 77
dummy.B = 77
dummy.C = 77
PrintL $CRLF + "now insert new element 2"
Heap_ElementInsertAt(VarPtr(foo(2).S1), 2, Memory_Get(VarPtr(dummy), SizeOf(t_Subtype)) )
ReDim dArray(HEAP_Size(foo(2).S1)\SizeOf(t_SubType)) As t_SubType At foo(2).S1
For i = 1 To UBound(dArray)
' PrintL "element" + Str$(i)
PrintL "A:" + dArray(i).A
PrintL "B:" + dArray(i).B
PrintL "C:" + dArray(i).C
PrintL
Next
PrintL $CRLF + "key to continue" + $CRLF
WaitKey
PrintL "new use of Heap_SetAt"
Heap_SetAt VarPtr(foo(3).S2), "this is important"
PrintL Heap_Get$(foo(3).S2)
' - - - - - -
String fish
PrintL $CRLF + "new : SetStr (replaces Set$ since does not return string)"
SetStr "fish", "apple juice"
PrintL Get$("fish")
PrintL
Dword myPtr = GetPtr "fish"
PrintL StrAtPtr$ myPtr
PrintL
PrintL fish
PrintL $CRLF + "key to end" + $CRLF
WaitKey
EDIT:
Functions-Overview version 0.42 - find a link to the latest version there
This attachements is an older version to run the posted examples before 12-08-2013.
MinVersion 1.9.7.0
Functions-Overview version 0.35
FileVersion 0.35, 07-08-2013
Bookmarks