[Gambas-devel] [Gambas-user] When to use GB.NewArray or GB.Array.New
Benoît Minisini
gambas at ...1...
Sat Feb 18 14:05:51 CET 2012
Le 16/02/2012 21:46, Randall Morgan a écrit :
> Hi,
>
> I am experimenting with arrays in C components. I have looked at the
> documentation on arrays and see that there are two types of arrays. It
> looks like GB.NewArray simply reserves memory and GB.Array.New creates a
> new GAMBAS array object.
>
> My question is: When is it appropriate to use each of these types. To me it
> seems that GB>NewArray would be used only for temporary memory allocation
> as in a function and therefore should be freed with GB.FreeArray before
> exiting the function. Also, that GB.ArrayNew would be used anytime you need
> a persistent array such as returning an array object or using the array as
> a class member/property. Is this correct?
>
> Thanks for the clarification!
>
>
(please use the developer mailing-list for such questions...)
GB.NewArray() and GB.FreeArray() allows you to create dynamic C arrays
whose allocation is managed by the interpreter. These arrays can grow
automatically as needed (with GB.Add or GB.Insert), or shrink (with
GB.Remove).
You use them when you need a array whose size is not static.
GB.Array.New creates a Gambas array object (Integer[], String[], and so
on). You use it when you need to return a Gambas array from a property
or a method.
Then you have two choices: either you create it and store it inside your
object structure, or you create it only when you return from the
property or method.
Regards,
--
Benoît Minisini
More information about the Devel
mailing list