[Gambas-user] Gambas 3 arrays usage

Emil Lenngren emil.lenngren at ...626...
Sun May 6 14:28:25 CEST 2012


Embedded arrays are declared like this:

Public ArrayOfStrings[5] As String

While normal arrays are declared like
Dim ArrayOfStrings As New String[5]
or
Public ArrayOfStrings As New String[5]

I can agree the documentation is maybe a bit strange...

Embedded arrays take upp less space since the data they contain are
directly allocated as a datafield in a class, but slower to use because a
wrapper object holding a reference is created every time you use it.
Embedded arrays can not be declarated as a local variable, because each
value on the stack always take up a constant memory usage in gambas (32
bytes for 64-bit platform), and arrays can be larger than that.

I suggest you should avoid embedded arrays. They are useful when you need
to create a struct containing an array that should be passed to an external
C function that expects such a struct, but not otherwise.

/Emil

2012/5/6 RICHARD WALKER <richard.j.walker at ...247...>

> Greetings to the list on a fine Sunday afternoon (should be outside
> enjoying it instead of hacking on a new project!).
>
> I am having difficulty understanding the correct way to program with
> arrays in Gambas 3. The documentation has this warning notice:
>
> In Gambas 3, embedded arrays cannot be used as local variables
> anymore. But they can be public!
>
> This is from http://gambasdoc.org/help/lang/arraydecl?show&v3
>
> The same page shows that local variables are declared as:
>
> (1) DIM Identifier AS [ NEW ] Datatype [ Array dimensions ... ]
>
> Embedded arrays are defined as being declared in this way:
>
> (2) [ STATIC ] { PUBLIC | PRIVATE } Identifier [ Array dimensions ...
> ] AS Native Datatype
>
> My difficulty is that I do not understand how an embedded array
> declared with syntax (2) can be taken for a local variable, which is
> declared with syntax (1). Is there some other non-technical meaning
> for "local variable" which is intended in the notice?
>
> Richard
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list