[Gambas-user] Question on string[]
Eilert
eilert-sprachen at ...221...
Tue Dec 14 17:55:58 CET 2004
Bonsoir Benoit,
Benoit Minisini schrieb:
> On Monday 13 December 2004 23:12, Laurent Carlier wrote:
>
>>Le Lundi 13 Décembre 2004 15:19, Eilert a écrit :
>>
>>>Hi,
>>>
>>>I just found that it's possible to re-define a module-public string
>>>array from within the same sub - is that allowed?
>>>
>>>static myArray as string[]
>>>
>>>sub myProcedure()
>>>.
>>>.
>>>.
>>> myArray = new string[]
>>>.
>>>.
>>> myArray.Add(something...)
>>>end sub
>>>
>>>So if I call myProcedure again, no complaint, and everything runs
>>>through again like expected :-) But - what happens here? Is myArray made
>>> again, i. e. like REDIM or is a copy made? Buffer overflow...?
>>>
>>>Rolf
>>
>>The first myArray is a global variable, the second one is a local variable.
>>In myProcedure sub, you have only access to the local one (as it have the
>>same name !) and of course this one is destroyed at the end of the sub.
>
>
> Mmm... No.
>
> myArray points at a String[] object. At start, myArray is NULL. Each time you
> call myProcedure(), you create a new String[] object, and make myArray points
> at this new array object. The old one is destroyed, provided that no other
> variable has a reference on it.
>
> Regards,
>
Well, now, is it allowed or depreciated? Will I run into problems if I
create a new String[] object over and over again (maybe because this sub
is called again and again?).
In my concrete project this is not the case, but I know how easily you
can run into such problems... :-)
And what do you mean "another variable has a reference on it"?
Rolf
More information about the User
mailing list