268 of 318
ZBasic System Library 258 ZX Microcontroller Family SizeOfU Type Function returning UnsignedInteger Invocation SizeOfU(var) Parameter Method Type Description var ByRef any type The variable whose size, in bytes, is desired. Discussion This function returns the number of bytes constituting the supplied variable. The primary purpose of this function is to allow writing code that is more easily maintained. For example, instead of hard coding the size value to pass to the OpenQueue() subroutine, you can use SizeOfU(queue) instead. When you change the size of the queue there will be no need to update the OpenQueue() calls. When used with arrays, you may give the array name without any index parameters and SizeOfU() will return the total number of bytes occupied by the array. Alternately, you may specify constant expressions for all of the array dimensions and SizeOfU() will return the number of bytes occupied by a single element of the array. This function is not particularly useful with sub-byte types (Bit and Nibble). The SizeOfU() function also allows the argument to name one of the fundamental data types (except String). In this case it returns the number of bytes comprising the type. For example, SizeofU(Integer) returns the value 2. Example Dim cnt as UnsignedInteger Dim val as Single Dim ia(1 to 20) as Integer cnt = SizeOfU(val) ' result is 4 cnt = SizeOfU(ia) ' result is 40 Compatibility This function is not available in BasicX compatibility mode. See Also SizeOf