[Gambas-user] Print SizeOf(t) 't is a string
Tobias Boege
taboege at ...626...
Wed Jul 29 20:10:45 CEST 2015
On Wed, 29 Jul 2015, nando wrote:
> Dim t As String
>
> Print SizeOf(t)
> Type mismatch: wanted integer, got string instead
>
> 'Sizeof also errors on a Stucture
>
> Ubuntu 14.04LTS
> Gambas 3.7.1
>
Do you realise that you were replying to a totally unrelated thread from
July 2013? Create a new thread (by writing a new mail instead of replying
to another one) next time.
The documentation[0] of SizeOf clearly states:
Size = SizeOf ( Datatype )
Return the memory used for storing a specific datatype.
Datatype can be one of the following constant:
Datatype Constant
Boolean gb.Boolean
Byte gb.Byte
Short gb.Short
Integer gb.Integer
[...]
If you want to know how many bytes a string variable takes, you have to use
SizeOf(gb.String)
but note that this returns the memory usage of the String datatype
(container) not any actual value. On my system SizeOf(gb.String) is 8 bytes,
for the pointer which references the actual string data container in the
interpreter. Doesn't sound very useful and really isn't :-)
The only possible use of SizeOf() which I can think of is when you want to
invoke libc's qsort() for a Gambas array (you get the datatype constant from
Array.Type).
Needless to say, SizeOf() cannot be used to measure the size a Struct would
take up on your system. You could maybe use SizeOf() on its contents...
Regards,
Tobi
[0] http://gambaswiki.org/wiki/lang/sizeof
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list