[Gambas-user] Pointer or something
Benoît Minisini
gambas at ...1...
Sun Oct 4 13:01:19 CEST 2015
Le 04/10/2015 12:48, Moviga Technologies a écrit :
> Well, just following the logic from variables. If a and b are integers,
> and b=2, and then one does a=b, and then Inc a, b is still 2 while a is
> 3.
I don't see the relation with structures. What you are talking about is
just the difference between a value and a reference (i.e. a pointer) to
a value.
>
> Oh, OK. I though using Struct was just a more simple alternative to a
> class. Better use a class then. Thanks!
>
In Gambas, a structure is a class. As soon as you use it exactly like a
class, there is no difference.
Struct MyStruct
...
End Struct
Private aStruct As MyStruct
Private aClass As MyClass
--> aClass and aStruct behave the same.
But there is something more when you use the Struct keyword in the
declaration:
' MyClass.class
Private aStruct As Struct MyStruct
Then the contents of the structure is embedded in the object where it is
declared. Consequently, to use it like another object (i.e.
MyObject.aStruct.XXX), Gambas has to create a temporary object, and so
it is slower than using a real object.
There is the same distinction with array of structures:
' MyClass.class
Private arrayOfStruct[XXX] As Struct MyStruct
arrayOfstruct[1] is slower than if the declaration has been:
Private arrayOfStruct As New MyStruct[XXX]
(note that in the late case, you have to create instances of MyStruct to
populate the array).
I hope it's a bit clearer now.
Regards,
--
Benoît Minisini
More information about the User
mailing list