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 03 '24 edited Nov 03 '24
So , I guess people are interested. :) So . Here is the general overview: We have a string, it's a combo of 8 string types in 1.
For small strings sizes ( less than 24 with custom allocators and less than 32 with the default allocator), we store it inside the object in a Small String buffer (SSO - O is object ).
For immutable strings it's in a heap string slice and we can share substrings of it with COW. ( the iterators are internally index based , so this shouldn't be bad).
For non immutable heap strings, it's basically like std string .
For known constant strings we use a const string slice that doesn't allocate memory.
The buffer string is a niche thing , dw about it.
The rope is basically a vector of strings with an internal allocator dedicated to it for a better memory layout . It uses some techniques related to string data sharing to achieve mutable string properties without actually changing the original string data . ( it can technically be a tree if the inner strings become ropes on their own)
The problem was, I made all of them except for the rope , and then realized that my allocator references were necessary. So I had to change the entire layout and im back at square 1.
I'll talk more if you were interested . Tell your opinions if you want.