1) what is the advantage of immutability of strings? In c#, operations on strings return a new object. Further, the note says that this greatly affects performance. Then why the hash table rows are there? What are the pros, what cons?
2) Write a program that works with strings (many times per second). And strings are used not only to display text, but also for encoding numbers, Boolean values, etc. are Planning to rely on "brain" of the language in this question. But what method of storing, processing, and conversion of strings is the most optimal in this case?
1. Immutability of strings is used in comparison operations - compares only pointers. Still have questions save space when re-using, but not sure there is a lot to win.
2. For the active string is just used StringBuilder. in fact, they represent the allocated array is large in size and which operates with the line. During manipulation, a new array is not created - everything is in place, if not exceeded the allocated size. If the buffer is not enough - is the new, larger size. Current size of the buffer can be found from the Capacity property, it can directly ask large enough.
Manuela.Ho answered on June 10th 19 at 16:37
For starters, you need to understand that a string is essentially an array of characters. The length of the array change is not accepted. It certainly can be done, but the operation changes the size of the array is very resource-intensive. The array is data that is written to memory sequentially. When you try to change the size of the array, there is no guarantee that after the last element in the array is available memory, therefore have to copy the array in free space. In fact, for this reason, the size of the array do not change.
In order to produce any operations over the line, you need to change an array of characters.
Gladyce57 answered on June 10th 19 at 16:39
1) Any comparison operations and sorting lines are much faster. Frequently used Dictionary dictionaries can be obtained very fast. And most importantly - in line will dotnet thread-safe
2)/3) do Not premature optimization, standard methods more than enough for the concatenation of strings of template strings ($""), StringBuilder, or a stream, if the volume is very large. String for encoding "numbers" is something unhealthy in architecture.
Leora answered on June 10th 19 at 16:41
If you can take, to allocate any chunk of memory to fit your needs, and then take and expand on it, without selecting a new parcel with the right size, this way you will be able to solve your problem. Just do it in C#, there is everything necessary for working memory. But can you handle it to avoid any errors and whether this solution is faster banal copy one memory area to another?