Похожие чаты

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 ответов

13 просмотров

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

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

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

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта