Похожие чаты

What is the maximum length of string? I imagine it can

be, at most, uint32 max so 4294967295 characters.

And each character is a byte so 34359738360 bits is a bit more than 4 gigabytes, this is for 32-bit systems. 64 is larger but aiming for 32-bit will probably be the safest for compatibility.

Can someone check my calculations?

11 ответов

7 просмотров

You can use len() function to get the length of a string, and len() returns a number with int type. Also from the runtime representation of a string, the Len field is of type int. And the int type is usually 32 bits on 32-bit systems and 64 bits on 64-bit systems.

Liλn-🌻 Автор вопроса
AngryMethane
You can use len() function to get the length of a ...

It’s int instead of uint? That seems inefficient. Can strings be negative length?

Liλn 🌻
It’s int instead of uint? That seems inefficient. ...

its useless but not a problem int of 64bits can represent until 9223372036854775807 -> over 8000 petabytes..

Character not always 1 bite

Liλn-🌻 Автор вопроса
🇺🇦 Anton
Character not always 1 bite

I know, a character is a rune. I was talking about an ASCII char actually

Liλn 🌻
It’s int instead of uint? That seems inefficient. ...

Why do you think int is less efficient than uint? uint has a few inconspicuous bugs

Liλn-🌻 Автор вопроса
AngryMethane
Why do you think int is less efficient than uint? ...

Such as? All I know is uint should be used for when no negative numbers are required. This is a clear example.

Liλn 🌻
Such as? All I know is uint should be used for wh...

You can run this piece of code package main import "fmt" func main() { var a uint8 s := "This is string" a = uint8(len(s)) - 1 for ; a >= 0; a-- { fmt.Printf("%c\n", s[a]) } }

Liλn-🌻 Автор вопроса
Liλn 🌻
Indexing strings by position is bad

This is just an example. s can be any type which can be iterated, such as a slice or an array.

Liλn-🌻 Автор вопроса
AngryMethane
Why do you think int is less efficient than uint? ...

You said “bug” this is not a bug. It’s literally an unsigned int, which has double capacity for positive numbers vs the same bit length int

Похожие вопросы

Обсуждают сегодня

что насчет пагинга? на осдеве непонятно(
Vi Chapmann 🪙
26
А как старый хаскел с новым стыковать ? потому как тут работает https://play.haskell.org/saved/C3xpMzcd, а вот тут https://stepik.org/lesson/7602/step/9?unit=1473 нет ошибка C...
Fedor
131
hey everyone I'm not able to input come characters in my flatpak apps, they get ignored by the application. all other non-flatpak apps are fine with these characters. I search...
elo
20
Guys what is ur real (no jokes) expectation of link price during this cycle?
Hobbyist
28
Hey everyone! How's your weekend going so far?
Noah Noure
17
Hey, it seems like a solid project for the gaming industry. What are your initial thoughts?
Josh
26
Вопрос я правильно понимаю что в коде newtype ArrowMap k v = ArrowMap { getArrowMap :: k -> Maybe v } getArrowMap есть функция типа k -> Maybe v, если да, то не понимаю задач...
Fedor
64
Ребят, что лучше для реверса: гидра или ида?
En Vind Av Sorg
26
Works for everyone else, you think think SOL organically went from $8 to $220? Of course it didn’t, they pumped it. First to $20 with the narrative it would go back to $100, ...
Yankee Ruin X
8
if (user?.choseType === 'oneDay') { await ctx.reply( 'Добро пожаловать в команду «Магнита»! Правда, на один день ☺️ ', ); await ctx.s...
Kokni
1
Карта сайта