[Gambas-user] some questions of: Struct
Benoît Minisini
gambas at ...1...
Mon Jan 17 03:18:07 CET 2011
> Benoit,
> 1) What version is struct implemented?
I think you want to know that structures are implemented in Gambas 3 only.
> 2) Reading and writing a struct to a stream (file, etc) is an exact copy of
> the struct?
Of course not. Data is serialized.
Writing (or reading) a structure is exactly like writing (or reading) each
field with the WRITE (or READ) instruction. This is done recursively if there
are structures inside structures.
Consequently, as soon as you don't use strings, the data written to the stream
will look like what is stored in memory, but without padding (see the next
question).
> 3) Does struct pad with bytes to fit alignments or is it exact
> as defined?
There is padding, so that an short is stored at a memory address multiple of
2, an integer or a single at a memory address multiple of 4, a long, a float
or a date at a memory address multiple of 8. A more complex datatype (a
pointer, an object reference, an embedded structure or array) is stored at an
address multiple of 4 on a 32 bits system, and at an address multiple of 8 on
a 64 bits system. Finally, an entire object is padded so that its size is a
multiple of 4 on a 32 bits system, and a multiple of 8 on a 64 bits system.
> 4) This is similar to RECORD in VB.
I don't know.
Regards,
--
Benoît Minisini
More information about the User
mailing list