From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=BAYES_40,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a05:622a:50d:: with SMTP id l13mr19104127qtx.75.1638519116967; Fri, 03 Dec 2021 00:11:56 -0800 (PST) X-Received: by 2002:a25:8804:: with SMTP id c4mr20745661ybl.148.1638519116759; Fri, 03 Dec 2021 00:11:56 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fdn.fr!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 3 Dec 2021 00:11:56 -0800 (PST) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=46.147.99.152; posting-account=niG3UgoAAAD7iQ3takWjEn_gw6D9X3ww NNTP-Posting-Host: 46.147.99.152 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: String Buffer From: Vadim Godunko Injection-Date: Fri, 03 Dec 2021 08:11:56 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:63197 List-Id: On Thursday, December 2, 2021 at 9:17:38 PM UTC+3, kevc...@gmail.com wrote: > In this thread bounded and unbounded get quite a bashing.=20 >=20 > "https://groups.google.com/g/comp.lang.ada/c/NINmFln-YS4/m/5De5DeUAAAAJ"= =20 >=20 > I thought bounded looked useful but then I realised that it allocates the= max immediately anyway. It may be useful in constrained environments but t= hen I do not use Strings in constrained environments.=20 >=20 > Unbounded is said to be inefficient because it re-allocates.=20 >=20 > In Go they have strings.Builder. I assume that is what Text_Buffer is aim= ed to be. (Actually Go seems to have copied a lot from Ada such as AWS API,= unless they both are similar to something else like JAVA).=20 >=20 > Is Text_Buffer usable today with GCC 11?=20 >=20 > strings.Builder in Go behaves similarly to unbounded in that it doubles t= he allocation as required but it only returns a string when needed and does= not have string operations. You can Grow the builder to avoid re-allocatio= ns.=20 >=20 > "https://pkg.go.dev/strings#Builder"=20 >=20 > If possible without breaking all of the string functions (length and sepa= rate capacity) and Unbounded Strings had a Grow function, then wouldn't tha= t relieve the efficiency issue?=20 >=20 > In any case avoiding unbounded strings is almost certainly in the realm o= f premature optimisation most of the alleged 10% of the time that it useful= , but it would be nice to know of and use something akin to strings.Builder= , preferably from the standard library, if it is available? For VSS.Strings.Virtual_String we used two kinds of optimization: 1. Short strings are stored without any memory allocation. It saves a lot o= f time. This is not very visible in multithread applications due to runtime= cost of controlled objects; however it is very visible on manycore due to = less amount of involved atomic operations. How "short" string should be de= pends from underlying encoding, content and machine architecture, on modern= 64bit systems when UTF-8 encoding is used it is 17 ASCII characters, or 8 = Cyrillic characters, or 4 math characters. In context of Ada Language Serve= r most of cases are such small strings. 2. It is possible to set capacity for the particular string object. Memory = will be reallocated on next modification operation of the string object. Th= is may be useful for large strings, when approximate size of the string is = known and allows to save few allocate/move memory cycles on append. I don't= know any real use cases of this feature right now.