07-17-2023, 07:04 PM
@SagraS - Thanks for the example and the description in German.
I tried a few things with the example to understand the whole thing. Well, it comes so slowly, understanding. The thing about _MEM is new for me in Basic.
The number in SEGBlock.TYPE obviously depends on the variable declaration, because it changes depending on the variable type. Is there a table showing what each number means?
What still surprises me is that with a 2nd number, the memory address increases by 8 bytes, but SEGBlock.SIZE and SEGBlock.ELEMENTSIZE only show 4 bytes (4 + 4?).
I tried a few things with the example to understand the whole thing. Well, it comes so slowly, understanding. The thing about _MEM is new for me in Basic.
The number in SEGBlock.TYPE obviously depends on the variable declaration, because it changes depending on the variable type. Is there a table showing what each number means?
What still surprises me is that with a 2nd number, the memory address increases by 8 bytes, but SEGBlock.SIZE and SEGBlock.ELEMENTSIZE only show 4 bytes (4 + 4?).
Code: (Select All)
'SagraS, Beispiel fuer die Nutzung von _MEM - 16. Juli 2023
' 32Bit / 64Bit Speicher (Der von Windows)
' Reine 32/64 Bit Adressierung
' 32/64 Bit Pointer
' Funktioniert fuer Werte mit bis zu 64Bit (Integer64)
Option _Explicit
Dim SEGBlock As _MEM
Dim As _Unsigned Long wert, wert1, wert2
Dim As _Offset position, position1
Print
Input "Zahl eingeben : ", wert
Print
Input "Noch eine Zahl: ", wert1
' Speicherblock der Variable ermitteln
SEGBlock = _Mem(wert)
'Entspricht der Startadresse
position = _Offset(wert)
position1 = _Offset(wert1)
' Aendern des Wertes im Speicher um -5 / +5
_MemPut SEGBlock, SEGBlock.OFFSET, _MemGet(SEGBlock, SEGBlock.OFFSET, Long) + 5 As LONG
' Wert aus dem Speicher holen
wert2 = _MemGet(SEGBlock, SEGBlock.OFFSET, Long)
Print
Print "Position erste Zahlim Speicher : "; position
Print
Print "Position zweite Zahlim Speicher : "; position1
Print
Print "Speicher Startadresse : "; SEGBlock.OFFSET
Print "Groesse des Blocks(Byte) : "; SEGBlock.SIZE
Print "Type des Blocks(Nummer) : "; SEGBlock.TYPE
Print "Datentyp des Blocks(Nach Dim) : "; SEGBlock.ELEMENTSIZE
Print "Neuer Inhalt der Speicheradresse: "; wert2
Print
'Startadresse bleibt gleich, es wird ja nur der Inhalt geaendert
Print "Startadresse neuer Inhalt : "; SEGBlock.OFFSET
' Speicherblock freigeben
_MemFree SEGBlock
End