Function/Operator in Dart to obtain size of a data type Function/Operator in Dart to obtain size of a data type dart dart

Function/Operator in Dart to obtain size of a data type


It does not really make much sense to have such an operator in a high-level programming language like Dart where the size of types can change by optimization on runtime and based on if fields in classes are used or not. If you need the size of a given type for debug purposely, I guess you can find some information by using the Dart Observatory:

https://dart-lang.github.io/observatory/

If the size of data is important on runtime, then use the dart:typed_data library where you have access to types there are documented with a specific size. E.g. Int8List which is documented as:

A fixed-length list of 8-bit signed integers.

And if you need to have the size because of programming against native libraries, there are in fact a sizeOf method in the new dart:ffi library which can only be used on the types in dart:ffi:

https://api.dart.dev/stable/2.7.1/dart-ffi/sizeOf.html