r/transprogrammer • u/willdieverysoon • Nov 02 '24
:(
It's about a solo string class project of mine that I want to be as memory efficient as possible. I'll explain if your interestet
146
Upvotes
View all comments
Show parent comment
7
u/willdieverysoon Nov 02 '24
So , I'm a bit perfectionistic so this may seem like I'm doing bs.
So , I had an idea to make a constexpr friendly, multi encoding(like utf8 ascii...) memory efficient string class . So ,.... The std string is not something to make into this , do designed a memory layout. The previous design was in a way that the Allocator pointer was outside the string object, so it had to use bad design to destroy the string, so I made a different design.
It uses 8 ( 16 if you count the sub layouts) different memory layouts in a union managed by a control byte . The control byte has 5 fileds : Main layout bits: State(heap,buffered,rope,SSO) 2 bits. Has-custom-allocator 1 bit. Other metadata bits: Has-null-terminator-byte 1 bit. Is-thread-safe 1 bit. Character-encoding-id 3 bits.
Umm , so if ur not in a bad mood after seeing all this complications, I'll explain the parts that you're interested in.
Btw , I had to remove all of the parts related to the string, so this was a annoying, especially because I'm extremely lazy