"mario bancos" <
[hidden email]> wrote in message
news:
[hidden email]...
> Hi,
>
> I'm wondering if there's any Class to map an ExternalAddress to a
> "PointerClass" of any ExternalStructure, like the CPointerType of
> VisualWorks.
>
In Dolphin ExternalStructures can be either 'value' (internal ByteArray) or
'reference' (pointer) instances.
> ie.
>
> ba := ByteArray new: 4.
> dwordpointer := PointerClass fromAddress: ba yourAddress type: DWORD.
> dwordPointer at: 1. "Read 4 bytes"
> wordpointer := PointerClass fromAddress: ba yourAddress type: WORD.
> wordPointer at: 1. "Read 2 bytes"
> wordPointer at: 2. "Read 2 bytes"
This is a slightly different thing - C confuses pointers and arrays, but you
don't really want pointers here, since then you lose important information
like the length. In Dolphin you would need to use a subclass of
ExternalArray. There is a generic one of these, StructureArray, which should
work for any structure, and some specialized ones that offer higher
performance for a limited range of types. There is also a slight difference
in behaviour which you will notice if you evaluate the examples below. For
example:
ba := ByteArray new: 4.
dwords := StructureArray fromAddress: ba yourAddress length: 1
elementClass: DWORD.
dwords at: 1. "Read 4 bytes - returned as an instance of DWORD that
references the original data"
words := StructureArray fromAddress: ba yourAddress length: 2 elementClass:
WORD.
words at: 1. "Read 2 bytes - returned as an instance of WORD that
references the original data"
words at: 2. "Read 2 bytes - ditto"
You must specify the length when you create the array. This allows for
bounds checking on indexed access, and also allows ExternalArray to
implement useful parts of the collection protocol such as do:, select: and
collect:.
Or:
The most direct way to rewrite your code would be:
dwords := DWORDArray new: 1.
dwords at: 1. "Read 4 bytes - returned as an integer"
words := WORDArray new: 2.
words at: 1. "Read 2 bytes - returned as an integer"
words at: 2. "Read 2 bytes - returned as an integer"
Regards
Blair