Тёмный

An Attempt at Making a Better String for C++ 

Mashpoe
Подписаться 114 тыс.
Просмотров 8 тыс.
50% 1

GitHub link for this project's source code: github.com/Mashpoe/cpp-string
Also please check out my website: mashpoe.com

Опубликовано:

 

26 янв 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 18   
@Mashpoe
@Mashpoe Год назад
I improved the string class a while after making this video. Now it uses an optimization called SSO, which is short for "small string optimization." This makes the code much nicer, and small/empty strings are now much less costly to create. The worst thing about the code from this video is that even empty strings allocate space on the heap. SSO fixes this. This video also gets the award for my worst thumbnail ever. Thanks for coming to my TED Talk.
@ybungalobill
@ybungalobill 2 года назад
You cannot rely on realloc for good performance: you may still get worst-case quadratic performance when building up a string from smaller pieces. Your benchmarks may show an improvement over std::string because your heap isn't fragmented yet. In a long running process with lots of malloc/free, realloc will need to frequently copy the string around. To avoid that you need to track the capacity separately from the length, and increase it exponentially -- which is what std::string does. I was also going to comment about SSO, but looking at your github code you already figured it out yourself; now your string also has 32 bytes overhead :)
@namehidden8854
@namehidden8854 2 года назад
Absolutely. Loading and running a search tree or even a string-based SVT would make for a better benchmark.
@AmaroqStarwind
@AmaroqStarwind 6 месяцев назад
Smart Pointers are the future!
@joshua2311
@joshua2311 3 года назад
This is some of the most interesting content I've seen in quite some time, thanks and keep it up
@kunstkritik
@kunstkritik 4 года назад
That was very interesting. One question though, why is the standard library string class how it is though? I mean, is it made for maximum safety or just backwards compatibility ?
@Mashpoe
@Mashpoe 4 года назад
I think it's backwards compatibility, and some of those features came after the original version of the standard library string, and now it's too late...
@antonyzhilin
@antonyzhilin 4 года назад
5:14 There's no temporary there since C++17
@unflexian
@unflexian 5 месяцев назад
you think you could make string concatenations do nothing for empty strings, for constexprs and such?
@conabe
@conabe 2 года назад
this is why i use c#
@REALsnstruthers
@REALsnstruthers 4 года назад
Don’t mind the Simon up in here He’s just gonna uh _yoink_
@jfk_the_second
@jfk_the_second 2 года назад
???
@ebebebeb7283
@ebebebeb7283 2 года назад
@@jfk_the_second means he's gonna steal the code
@MatheusAugustoGames
@MatheusAugustoGames 3 года назад
Copy and move constructors give me headaches....
@sander_bouwhuis
@sander_bouwhuis 4 года назад
Thanks! I have my own CWString class because std::wstring can't be safely used across exe/dll boundaries. I'll have a look at your code to see tips on how to improve my own code.
@m4rt_
@m4rt_ Год назад
(strcpy isnt safe)
@LiqqaRoni-cx3tx
@LiqqaRoni-cx3tx 8 месяцев назад
It's as safe as the programmer. Always check for errors and assume your functions callers will pass garbage.
@jfk_the_second
@jfk_the_second 2 года назад
10th comment! 😂
Далее
Improving My String Library
4:27
Просмотров 1,5 тыс.
31 nooby C++ habits you need to ditch
16:18
Просмотров 717 тыс.
КИТАЕЦ ЗА 24 МИЛЛИОНА / РАЗГОН
1:10:06
how NASA writes space-proof code
6:03
Просмотров 2 млн
Expanding the UTF-8 Character Set to Infinity
4:23
Просмотров 4 тыс.
How to make your STRINGS FASTER in C++!
15:02
Просмотров 115 тыс.
The Flaws of Inheritance
10:01
Просмотров 884 тыс.
Creating My Own String Library in C
4:42
Просмотров 9 тыс.
What is a Monad? - Computerphile
21:50
Просмотров 591 тыс.
I Made Minecraft, but It's 4D
13:48
Просмотров 4,9 млн
4D Miner Q&A Video #1
10:06
Просмотров 84 тыс.
КИТАЕЦ ЗА 24 МИЛЛИОНА / РАЗГОН
1:10:06