Pointer in Basic
#4
New Method
Code: (Select All)

' 32Bit / 64Bit Speicher (Der von Windows)
' Reine 32/64 Bit Adressierung
' 32/64 Bit Pointer
' Funktioniert fuer Werte mit bis zu 64Bit (Integer64)
DIM SEGBlock AS _MEM
DIM wert AS _UNSIGNED LONG
DIM wert2 AS _UNSIGNED LONG

wert = 4294967295

' Speicherblock der Variable ermitteln
SEGBlock = _MEM(wert)

' Aendern des Wertes im Speicher um -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 "Speicher Start Adresse  :"; SEGBlock.OFFSET
PRINT "Groesse des Blocks      :"; SEGBlock.SIZE
PRINT "Typ des Blocks          :"; SEGBlock.TYPE
PRINT "Datentyp des Blocks      :"; SEGBlock.ELEMENTSIZE
PRINT "Wert der Speicher Adresse:"; wert2

' Speicherblock freigeben
_MEMFREE SEGBlock

Old Method:
Code: (Select All)
' 16 Bit Speicher (Wird emuliert von QB64)
' Es handelt sich hierbei um DOS Adressierungen
' 16 Bit Pointer (Segment Adressierung im Speicher)
' Funktioniert nur fuer 1 Byte Werte 0 - 255
DIM SpeicherAdresse AS LONG
DIM wert AS LONG

wert = 65535

DEF SEG = VARSEG(SpeicherAdresse)

' Bei groesseren Variablen muss die Zahl zerlegt werden.
' Zerlegung der Variable in Bytes, die dann in den Speicher geschrieben werden
POKE SpeicherAdresse + 0, (wert AND &HFF00&) / &H100&
POKE SpeicherAdresse + 1, (wert AND &HFF&)

' Aendern des Wertes im Speicher um -5
POKE SpeicherAdresse + 1, PEEK(SpeicherAdresse + 1) - 5

' Zusammensetzung des Integer Wertes aus dem Speicher
wert2 = PEEK(SpeicherAdresse + 0) * &H100& + PEEK(SpeicherAdresse + 1)

PRINT "Verwendeter Segment Block: &H" + HEX$(VARSEG(SpeicherAdresse))
PRINT "Speicher Start Adresse  : &H" + HEX$(VARPTR(SpeicherAdresse))
PRINT "Wert der SpeicherAdresse :"; wert2
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: 7 Guest(s)