sirisian / ecmascript-types

ECMAScript Optional Static Typing Proposal http://sirisian.github.io/ecmascript-types/
453 stars 4 forks source link

Calculating the size of value types and ensuring compile-time optimization #77

Open sirisian opened 1 year ago

sirisian commented 1 year ago

A keyword or function that returns the number of bytes of an object. This would include class value types which have a fixed size.

Languages handle this slightly differently, but with similar results. C++ has a sizeof T keyword. C# has sizeof(T).

Since value types aren't Objects I find the idea of Object.size(...) or Object.size<T>() weird. Also I'd prefer more of a compile-time and runtime compatible method that is compiled away when applicable. Getting the size of uint8 for instance might be more readable than writing 1, but I'd hate if calculating the size had any performance implications.