Pointer in Basic
#9
@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?).

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
[Image: MEM-Uebung2023-07-17.jpg]
Reply


Messages In This Thread
Pointer in Basic - by Kernelpanic - 07-16-2023, 09:57 PM
RE: Pointer in Basic - by bplus - 07-16-2023, 10:17 PM
RE: Pointer in Basic - by mnrvovrfc - 07-17-2023, 12:05 AM
RE: Pointer in Basic - by SagaraS - 07-17-2023, 12:17 AM
RE: Pointer in Basic - by OldMoses - 07-17-2023, 12:40 AM
RE: Pointer in Basic - by bplus - 07-17-2023, 01:00 AM
RE: Pointer in Basic - by a740g - 07-17-2023, 02:53 AM
RE: Pointer in Basic - by SpriggsySpriggs - 07-17-2023, 11:55 AM
RE: Pointer in Basic - by Kernelpanic - 07-17-2023, 07:04 PM
RE: Pointer in Basic - by SagaraS - 07-17-2023, 09:39 PM
RE: Pointer in Basic - by mnrvovrfc - 07-17-2023, 10:52 PM
RE: Pointer in Basic - by Kernelpanic - 07-18-2023, 12:17 AM
RE: Pointer in Basic - by SagaraS - 07-18-2023, 02:42 AM
RE: Pointer in Basic - by bplus - 07-18-2023, 12:39 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 04:13 PM
RE: Pointer in Basic - by Kernelpanic - 07-18-2023, 04:26 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 04:59 PM
RE: Pointer in Basic - by SagaraS - 07-18-2023, 04:49 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 05:04 PM
RE: Pointer in Basic - by mnrvovrfc - 07-18-2023, 08:15 PM
RE: Pointer in Basic - by SagaraS - 07-18-2023, 07:30 PM
RE: Pointer in Basic - by SMcNeill - 07-18-2023, 10:11 PM
RE: Pointer in Basic - by SagaraS - 07-19-2023, 10:27 AM
RE: Pointer in Basic - by SMcNeill - 07-19-2023, 01:42 PM
RE: Pointer in Basic - by DSMan195276 - 07-19-2023, 11:15 PM



Users browsing this thread: 8 Guest(s)