Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But this still takes 9 bytes (at least) to store a tagged uint8_t.


The article's approach requires 8 bytes, plus a separate array of 1 byte tags.

The article reduces it to 4 bytes, plus an array of 1 byte tags, by dropping the requirement for a 64 bit member.

If we have to grow the array, we have to do two reallocations.

Caching is worsened: the tag and content are going to be in separate cache lines.


The final approach in the article is an array for each unique object size plus tagged indices/pointers. This would take one byte per uint8_t and doesn't suffer from the problems you mention, though it does have others. If memory pressure is your main problem it's a big win.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: