List element offsets...
Posted: Sun Aug 17, 2003 6:42 pm
OK, I'm not really a PB beginner, but I've never been too great with low-level memory access, pointers, etc, so I thought I'd post here!
I thought that a structure list of long values, like this...
... would mean each element took 4 bytes, so I imagined each entry in the list could be read via peeking @mylist (), @mylist () + 4, @mylist + 8, etc. However, it seems that each entry here is taking up 24 bytes instead of 4.
Could someone explain why this is? No doubt the answer is really obvious, but it's just not coming to me!
Example code (turn debugger on):
Basically, I was hoping to pass @mylist () as the address of an "array of long values" to an OS function (so I can easily add and remove items without having to re-Dim arrays, manipulate banks of memory, etc)...
I thought that a structure list of long values, like this...
Code: Select all
Structure Example
entry.l
EndStructure
Could someone explain why this is? No doubt the answer is really obvious, but it's just not coming to me!
Example code (turn debugger on):
Code: Select all
; Create a structure of long values...
Structure Handles
notifier.l
EndStructure
; Create a list using this structure...
NewList changes.Handles ()
; Add some elements to it...
For a = 0 To 2
AddElement (changes ())
changes ()\notifier = Random (1000)
Next
; Print contents...
Debug "Contents of changes () list:"
ResetList (changes ())
While NextElement (changes ())
Debug Str (changes ()\notifier)
Wend
; Show peeked longs from list...
FirstElement (changes ())
Debug ""
Debug "Peeked (wrong results):"
Debug PeekL (@changes ())
Debug PeekL (@changes () + 4)
Debug PeekL (@changes () + 8)
Debug ""
Debug "Peeked (right results):"
Debug PeekL (@changes ())
Debug PeekL (@changes () + 24)
Debug PeekL (@changes () + 48)