Video wird geladen...
Video konnte nicht geladen werden
I made a string library from scratch in C. Here's how and why Chapters: 00:00 - Intro 00:15 - Why 02:26 - First style - struct 05:16 - Second - Pascal style 06:50 - Comparing approaches 10:20 - single-header details 11:30 - Library implementation tour 15:05 - Splitting strings... show more
23,813 Aufrufe • vor 3 Monaten •via X (Twitter)
33 Kommentare

Вы молодец! Но интересно не это, а то что такой контент в текущее время безусловно для многих интересен, а для кого то вообще экзотика, хотя должно быть наоборот. Контент в котором детей учат считать и рассказывают про «счетные палочки» должен быть на детских каналах, а до взрослых каналов текущая «индустрия» вообще не доросла Вернее так: индустрия уже деградировала до того что смотреть про «счетные палочки» интересно и что-то «новое», дальше двинут совсем в идиотов которые даже на пальцах считать не умеют

Ну в целом да, это прям основа-основ, но очень много людей её скипают и кидаются сразу формошлёпить. Потом их заменяют ИИшкой, и некоторые, поняв, что произошло, возвращаются к основам. И тут появляюсь я )))

Да, я и говорю что ты молодец. Чего не могу сказать про «многих» 🙂

I also believe Pascal got strings correct vs the null terminated nonsense. (it stores the length first and then the string follows)

A trick I also love is xor a ASCII character with space to make it from upper to lower or lower to upper case.

У redis толковая реализация строк в составе, sds, пожалуй, одна из лучших. В любом случае, строки и без сборщика мусора это всегда больно

Да не, с аренками и стрингбилдерами норм

Yay ill have what to watch during lunch now

very pascal coded imo

One time I needed to write a metaprogramming utility(we might've discussed this IRL :D) and at first I thought I'd write the v0 in Python, but then it occurred to me to just clone the exact usage I would want from Python -- and to my surprise, all I needed were 3 functions.

Very nice, especially the int64_t size. In java (even 64 bit java) the native max string size is hold on a signed int32, meaning java code is stuck with max 2Gb strings, which is tiny for 2026 data needs. Your C code could inspire some Java folks to develop a big string library.

Nice

I started with Tsoding's view library about a year ago and added some utilities for parsing and it's been pretty great (I only wish there was something similar in stdlibc)

I knew that Tsoding has his own string view library, but I intentionally avoided it so I don't spoil the implementation, which is the most fun part for me in this whole side quest :)

What do you think number of string libraries in C is out there in total... back in the "prime" years of C, it seem like every one wrote their own personal stdlib extension lib. that they used for their projects 🤣 ... strings, dynamic arrays, what else was a must? ( In before Tsoding materializes out of nowhere ). Have to watch this after work!

Emacs!

Yay!

The null terminator is just 1 byte, your approach seems unnecessary and overkill with no clear benefits

You don't need to iterate over string every time you need to count it, and you can have many different views into the same character array - so allocation-free substrings

What about the additional memory needed to store the count?

@valigo In a memory unsafe language like C knowing the exact size at all times is worth the extra memory to make it easier to work with and avoid mistakes.

@valigo I thought the null terminator already has that covered pretty well and just 1 byte of memory required, of course you need to run through the string each time but you can then discard the count and not have it floating around, eating up that additional 3 bytes

@valigo working with C strings is very error prone and you also don't account for things like injecting a null into a string from user input, etc. There's a place for C strings but if you want to do fancy string manipulations something like this is far better than 1970s stdlib

@valigo You make a great point with the data corruption issue. Thanks for explaining, I think the upside is more clear to me

Единственное что я бы сделал по-другому, это префикс такой же как имя структуры. Почему-то так гораздо приятнее, автодополнение дополняет имя класса, ставишь _ и сразу все "методы".

Я думал об этом, но префикс с большой буквы меня смутил, поэтому надо было либо структуру делать с маленькой, либо префикс с большой. Решил пока попробовать вот так гибридно. Если приживется, наверное структурку сделаю string просто

your curiosity i like it

Лень смотреть

No jai, disliked

Very cool work! Since the split function is allocation free, we don't expect the input string to be tampered with after the split right? Have you considered Zig's iterator approach which just yields the 'String' just split. Caller still allocates if they want to

8:14 - Jet?

I think it was just a loud car lol

🤣 Great video
