[Gambas-user] Struct with Array Field

BB adamnt42 at gmail.com
Mon Apr 10 09:32:43 CEST 2023


I am only going to address the following.

On 9/4/23 5:34 am, Mayost Sharon wrote:
> If I have a structure that contains many array variables, etc.
> If I need to do NEW on every variable that is an array
> Why do I need it inside the structure?
> Is there a way in NEW once to execute on all variables?
>
> Thanks

Object initialisation is expensive. Object declaration is cheap.

In the latter all that is needed is that the pointer be established. In 
the former, the pointer and the target need to be established.

If the object is not needed then automatic initialisation could be 
extremely expensive depending on the complexity of the object. I realize 
that you are only talking about arrays but then again if you have "many 
array variables" inside the structure do you really want to incur the 
expense of creating them? Are they always going to be needed "immediately"?

I quite like the fact that object initialisation in Gambas is definite 
and "on demand" as our complex data objects that only use certain bits 
rarely do not incur the initialisation expense until they are needed. To 
give a finite example, one has properties that are both complex and 
"large" objects in themselves and are needed once a month. I certainly 
don't want to incur the expense of initialising them hundreds of times a 
day when the containing class is used in normal "daily processing".

hth

bruce



More information about the User mailing list