Memory List for Strings & Numbers
Posted: Mon Oct 18, 2021 7:14 pm
Now you can have numerical values and strings in the same list and check its size if needed. And if you allocate memory/string names before your allocated data, you can call on and search your memory data by name. It can be become like a memory Preference.

Code: Select all
NewList MemoryList() ;Create a new memory list.
For MemAddress = 0 To 9 ;Save multiple memory addresses in our list.
AddElement(MemoryList())
If MemAddress = 3
MemoryList() = AllocateMemory(80)
PokeI(MemoryList(), 0123456789)
Else
MemoryList() = AllocateMemory(1)
EndIf
Next MemAddress
SelectElement(MemoryList(), 6) ;Resize and add text to the 7th memory list element.
string.s = "Hello! I'm poking the memory with text."
bytes = StringByteLength(string.s) +2
MemoryList() = ReAllocateMemory(MemoryList(), bytes)
PokeS(MemoryList(), string.s, bytes)
ResetList(MemoryList()) ;Read back the memory addresses and their size.
While NextElement(MemoryList())
Debug MemoryList()
Debug MemorySize(MemoryList())
If ListIndex(MemoryList()) = 3 ;Lets peek at our memory integer.
Debug PeekI(MemoryList())
ElseIf ListIndex(MemoryList()) = 6 ;Lets peek at our memory string.
Debug PeekS(MemoryList())
EndIf
FreeMemory(MemoryList()) ;Will free on exit but good practice.
Wend
FreeList(MemoryList()) ;Will free on exit but good practice.