Closed Heziode closed 1 week ago
So, the Unbounded String max length is 32_767 elements.
It is at least 32_767 elements. In practice on almost all platforms, native or otherwise, Integer'Last
will be 2**31-1
.
If someone wants to process a large (unbounded) string, it could be interesting to redirect it to another type, like GNATCOLL.Strings for instance.
GNATCOLL.Strings
has the same indexing subtype (Natural
), so if you ever were to use a platform where Integer
is too small, you would have the problem with both unbounded string types. That's however very unlikely.
@gusthoff if you agree, let's keep this to reformulate along the lines of "their maximum length is Integer'Last". It might be worthwhile to precise that the big difference between bounded and unbounded is the use of heap allocation.
@gusthoff if you agree, let's keep this to reformulate along the lines of "their maximum length is Integer'Last". It might be worthwhile to precise that the big difference between bounded and unbounded is the use of heap allocation.
Yes, I've just added an admonition that explains these details. Thanks for suggestion!
In the String page, we can see this:
https://github.com/AdaCore/learn/blob/2183de64d50bf6c59e4413e8dd475fd4ee4fd552/content/courses/intro-to-ada/chapters/standard_library_strings.rst#L19-L20
The fact is, in computer, there is no infinite size. The majority of people will never reach the limit, but the fact is:
And from 3.5.4 Integer Types#21:
So, the Unbounded String max length is 32_767 elements. If someone wants to process a large (unbounded) string, it could be interesting to redirect it to another type, like
GNATCOLL.Strings
for instance.