[Gambas-user] About arrays
Benoît Minisini
gambas at ...1...
Tue Nov 23 19:13:27 CET 2010
Hi,
This is a clarification about Gambas arrays for Demosthene and all who
answered him.
There are two kinds of arrays in Gambas:
- "Normal" arrays.
- "Embedded" arrays.
Fabien used the word "static" arrays for "embedded" arrays because this was
the word I used first. Then I changed to "embedded" to avoid any confusion
with the "STATIC" keywords, which is not related at all.
"Normal" arrays are true Gambas objects. They have their own memory
allocation, and they are destroyed when they are not referenced anymore.
To declare a "normal" array, you can do:
(1) Dim NormalArray As Type[]
(2) Dim NormalArray As Type[] = [ ... ]
(3) Dim NormalArray As Type[] = New Type[A, B]
(4) Dim NormalArray As Type[A, B]
(1) declares an object variable that can receive a reference to a array whose
type is "Type[]". "Type" can be a native datatype or a class name. Note that
in Gambas 2, "Type" can only be a native datatype.
(2) declares an object variable, and initializes it with a new array created
by the [ ... ] operator.
(3) declares an object variable, and initializes it with a new array hainvg
the specified dimension.
(4) is a shortcut to the (3) syntax.
"Embedded" arrays are arrays that are allocated *inside* another object. They
don't have a memory allocation on their own, and they are automatically freed
with the object including them.
"Embedded" arrays are always member of a class or a structure only.
To declare an "embedded" array, you do the following:
[Static] {Private|Public} EmbeddedArray[A, B] As Type
There, "Type" is the datatype of one element of the array. There is no "[]"
after the type, unless you want to store array references inside the array of
course.
"Embedded" arrays can be static or not, public or private.
"Embedded" arrays are a little bit slower than normal arrays.
They were created to mimic C arrays (like Gambas structures, that were created
to mimic C structures), so that working with extern C functions using arrays
and structures is possible.
So you should not use them, unless you are working with extern functions.
I hope Gambas arrays are clearer now!
Regards,
--
Benoît Minisini
More information about the User
mailing list