sizeMinusHeader

BlitzMax Forums/BlitzMax Beginners Area/sizeMinusHeader

Yue(Posted 2015) [#1]
Hello, I have a concern, this method of collections returns the number of items in a collection multiplied by 4 ?, At what this is?


Floyd(Posted 2015) [#2]
If you have something like an array of user defined types then these are just pointers to the actual objects. A pointer is four bytes.

The array elements don't point to anything until you use New. That will allocate memory, but the array itself has not gotten any larger. It is still NumberOfArrayElements * 4 bytes.


Yue(Posted 2015) [#3]
Thank you very much, meaning that the more elements, more memory consumes a collection?


Mr. Goober(Posted 2015) [#4]
If you define an array of X elements, the size of the array is X*4 bytes. Some exceptions to this are arrays of Long (8 bytes per array cell), Short (2 bytes each), and Byte (1 byte each). All Type defined arrays are 4 bytes each, and also Strings (they are Objects).


TomToad(Posted 2015) [#5]
Does SizeOf really have any use in BlitzMAX? Generally, you wouldn't need to know the number of bytes a type or object will use unless it is being passed to a c/c++ module that requires it. Even then, you could use MyArray.length*4(or 8 or 2 depending on the type) or MyString.Length*2.