2 ms·
What is not considered in the article is to replace pointers to pages and patterns with handles that are tagged indexes into internal arrays. The big plus is t
by _0w8t 3y ago
What is not considered in the article is to replace pointers to pages and patterns with handles that are tagged indexes into internal arrays.
The big plus is the index tag allows to detect use after free and other memory safety bugs in wast majority of cases greatly improving memory safety.
If one then expose this handle as a generic typedef type over some integer type, then the API will be not type-safe, but the type mismatch will be detected very early.
Another option is to wrap the handle into separated structs for type safety. Then the caller will need to convert from specific handle for page, pattern etc. to the base handle when calling common draw operations. But that will be a simple operation like page.base or pattern.base, not MYLIB_PATTERN_TO_BASE(pattern). The drawback is that the caller will be able to construct wrong handles via struct initialization, but that is a big abuse and the type mismatch will still be detected at runtime.