Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Counting in binary is just like counting in decimal -- if you are all thumbs. -- Glaser and Way


devel / comp.lang.ada / Re: String Buffer

SubjectAuthor
* String BufferKevin Chadwick
+* Re: String BufferJeffrey R.Carter
|+* Re: String BufferDmitry A. Kazakov
||`* Re: String BufferJeffrey R.Carter
|| +* Re: String BufferDmitry A. Kazakov
|| |`- Re: String BufferKevin Chadwick
|| `- Re: String BufferRandy Brukardt
|`- Re: String Bufferldries46
+- Re: String BufferSimon Wright
`- Re: String BufferVadim Godunko

1
String Buffer

<c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6356&group=comp.lang.ada#6356

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:e0c:: with SMTP id y12mr13481314qkm.109.1638469057833;
Thu, 02 Dec 2021 10:17:37 -0800 (PST)
X-Received: by 2002:a25:8804:: with SMTP id c4mr16564332ybl.148.1638469057679;
Thu, 02 Dec 2021 10:17:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 2 Dec 2021 10:17:37 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=84.92.86.82; posting-account=5K6RMgoAAADQeoHIOMi2dg5aYc0IVxGi
NNTP-Posting-Host: 84.92.86.82
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
Subject: String Buffer
From: kevc3...@gmail.com (Kevin Chadwick)
Injection-Date: Thu, 02 Dec 2021 18:17:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 30
 by: Kevin Chadwick - Thu, 2 Dec 2021 18:17 UTC

In this thread bounded and unbounded get quite a bashing.

"https://groups.google.com/g/comp.lang.ada/c/NINmFln-YS4/m/5De5DeUAAAAJ"

I thought bounded looked useful but then I realised that it allocates the max immediately anyway. It may be useful in constrained environments but then I do not use Strings in constrained environments.

Unbounded is said to be inefficient because it re-allocates.

In Go they have strings.Builder. I assume that is what Text_Buffer is aimed 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).

Is Text_Buffer usable today with GCC 11?

strings.Builder in Go behaves similarly to unbounded in that it doubles the 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-allocations..

"https://pkg.go.dev/strings#Builder"

If possible without breaking all of the string functions (length and separate capacity) and Unbounded Strings had a Grow function, then wouldn't that relieve the efficiency issue?

In any case avoiding unbounded strings is almost certainly in the realm of 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?

Re: String Buffer

<sob8df$vbj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6358&group=comp.lang.ada#6358

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: String Buffer
Date: Thu, 2 Dec 2021 20:56:31 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <sob8df$vbj$1@dont-email.me>
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Dec 2021 19:56:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a3e10bdc35821c0508dd61d5653954ec";
logging-data="32115"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mIJwq8IVWmTa5xIfxbZ6hKVN9Qvu9v3k="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.3.1
Cancel-Lock: sha1:22Ss4k82ntHUywpXtIp1BB0ITio=
In-Reply-To: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Thu, 2 Dec 2021 19:56 UTC

On 2021-12-02 19:17, Kevin Chadwick wrote:
>
> Unbounded is said to be inefficient because it re-allocates.
>
> In any case avoiding unbounded strings is almost certainly in the realm of premature optimisation
"Efficiency" is only meaningful in the context of a project's quantitative
timing requirements: an efficient implementation allows the project to meet
those requirements, while an inefficient implementation does not.

In the absence of such context, any claims of "inefficiency" (and especially
blanket claims such as "Unbounded_String is inefficient") simply demonstrate the
speaker's incompetence.

For an example of context, a decade ago I worked on a soft-real-time system that
made extensive use of Unbounded_String and had no problem meeting its timing
requirements. Unbounded_String was clearly efficient for that project. Since
most projects that would use Unbounded_String have even less restrictive timing
requirements than that system, it seems likely that Unbounded_String will be
efficient for them, too.

--
Jeff Carter
"After fifteen minutes I wanted to marry her, and
after a half hour I completely gave up the idea of
snatching her purse."
Take the Money and Run
136

Re: String Buffer

<sob9gf$5mh$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6359&group=comp.lang.ada#6359

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!3s634R+rSk3f11Qz2WJrTw.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: String Buffer
Date: Thu, 2 Dec 2021 21:15:11 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sob9gf$5mh$1@gioia.aioe.org>
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
<sob8df$vbj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="5841"; posting-host="3s634R+rSk3f11Qz2WJrTw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 2 Dec 2021 20:15 UTC

On 2021-12-02 20:56, Jeffrey R.Carter wrote:
> On 2021-12-02 19:17, Kevin Chadwick wrote:
>>
>> Unbounded is said to be inefficient because it re-allocates.
>>
>> In any case avoiding unbounded strings is almost certainly in the
>> realm of premature optimisation

I see it as a design question. Code that modifies a string as a whole is
most likely broken. Unbounded_String property of varying length is not
needed except for very special cases, like passing parameters where no
result is allowed, e.g. in the task entries. Most, if not all such cases
are Ada language design deficiencies. Normally there should be no need
for Unbounded_String.

> In the absence of such context, any claims of "inefficiency" (and
> especially blanket claims such as "Unbounded_String is inefficient")
> simply demonstrate the speaker's incompetence.

It is true only to a certain degree. When comparing algorithms it is
valid to claim inefficiency without any context if computational
complexity sufficiently differs.

For example, an O(N) algorithm is unquestionably inefficient comparing
to O(log N) one. I leave marginal cases of very small N.

Unbounded_String uses storage pool and that is a qualitative difference
that requires in any context. For very large text buffers they are
unusable either. Again, it is a design question, any time I see
Unbounded_String alarm bells start ringing.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: String Buffer

<lylf12wx0t.fsf@pushface.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6361&group=comp.lang.ada#6361

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!8nKyDL3nVTTIdBB8axZhRA.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: String Buffer
Date: Thu, 02 Dec 2021 20:51:30 +0000
Organization: Aioe.org NNTP Server
Message-ID: <lylf12wx0t.fsf@pushface.org>
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="36604"; posting-host="8nKyDL3nVTTIdBB8axZhRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
Cancel-Lock: sha1:PaHsoWTTx0ubL2dKou60wg+r0Iw=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Simon Wright - Thu, 2 Dec 2021 20:51 UTC

Kevin Chadwick <kevc3no4@gmail.com> writes:

> In Go they have strings.Builder. I assume that is what Text_Buffer is
> aimed 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).
>
> Is Text_Buffer usable today with GCC 11?

If you mean Universal Text Buffers, no. There is
Ada.Strings.Text_Output, but it looks as though that's actually an
internal package to support T'Put_Image - so probably best avoided.

GCC 12 has universal text buffers.

But I don't see that Ada.Strings.Text_Buffers.Unbounded is going to be
any more or less efficient than Unbounded_Strings?

I seem to remember that AdaCore made considerable performance
improvements to Unbounded_Strings, for example copy-on-write sharing.

Re: String Buffer

<sobcg4$tc4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6362&group=comp.lang.ada#6362

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: String Buffer
Date: Thu, 2 Dec 2021 22:06:09 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <sobcg4$tc4$1@dont-email.me>
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
<sob8df$vbj$1@dont-email.me> <sob9gf$5mh$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Dec 2021 21:06:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a3e10bdc35821c0508dd61d5653954ec";
logging-data="30084"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18l4TQ4hXzbZNrdZ9kkVZLfDJ0p5Ej3R0I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.3.1
Cancel-Lock: sha1:vyMRIqIzliihpeJnFclxzxvCvgw=
In-Reply-To: <sob9gf$5mh$1@gioia.aioe.org>
Content-Language: en-US
 by: Jeffrey R.Carter - Thu, 2 Dec 2021 21:06 UTC

On 2021-12-02 21:15, Dmitry A. Kazakov wrote:
>
> It is true only to a certain degree. When comparing algorithms it is valid to
> claim inefficiency without any context if computational complexity sufficiently
> differs.
>
> For example, an O(N) algorithm is unquestionably inefficient comparing to O(log
> N) one. I leave marginal cases of very small N.

This is false. If you have the O(N) algorithm and it meets your requirements,
then using it is more efficient than implementing the O(log N) algorithm. If you
have both and the O(N) algorithm meets your requirements, the effort to get your
data into a form where you can apply the O(log N) algorithm may still outweigh
the time difference.

As for "very small N", I have worked on systems where linear search was
efficient for sequences of 100,000 items.

The only thing you can meaningfully say about such algorithms is that one is
O(N) and the other O(log N). Both have their uses.

Unbounded_String is needed far less than many people think, but there are
application domains where it is much easier to achieve correctness and clarity
with a variable-length string abstraction than without. Blanket statements about
"efficiency" are dangerous for those working in such domains.

--
Jeff Carter
"After fifteen minutes I wanted to marry her, and
after a half hour I completely gave up the idea of
snatching her purse."
Take the Money and Run
136

Re: String Buffer

<sobepr$h88$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6363&group=comp.lang.ada#6363

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!3s634R+rSk3f11Qz2WJrTw.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: String Buffer
Date: Thu, 2 Dec 2021 22:45:32 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sobepr$h88$1@gioia.aioe.org>
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
<sob8df$vbj$1@dont-email.me> <sob9gf$5mh$1@gioia.aioe.org>
<sobcg4$tc4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="17672"; posting-host="3s634R+rSk3f11Qz2WJrTw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 2 Dec 2021 21:45 UTC

On 2021-12-02 22:06, Jeffrey R.Carter wrote:
> On 2021-12-02 21:15, Dmitry A. Kazakov wrote:
>>
>> It is true only to a certain degree. When comparing algorithms it is
>> valid to claim inefficiency without any context if computational
>> complexity sufficiently differs.
>>
>> For example, an O(N) algorithm is unquestionably inefficient comparing
>> to O(log N) one. I leave marginal cases of very small N.
>
> This is false. If you have the O(N) algorithm and it meets your
> requirements, then using it is more efficient than implementing the
> O(log N) algorithm.

You have to show that it meets these requirements. The burden of proof
is on you as you select an objectively inferior algorithm. Selecting a
better algorithm is a safe choice under ill-defined conditions.

> Unbounded_String is needed far less than many people think, but there
> are application domains where it is much easier to achieve correctness
> and clarity with a variable-length string abstraction than without.
> Blanket statements about "efficiency" are dangerous for those working in
> such domains.

It is a good argument because introducing String requires more initial
efforts in Ada than a thoughtless application Unbounded_String.

And note, that in most cases it is really thoughtless as the choice is
made on the basis of how easy it is to declare a string component of a
record type and then rewrite it.

Later on throughout the rest of the program the user of Unbounded_String
will be consistently punished for that poor choice because normal string
operations are very uncomfortable with Unbounded_String. But that
happens later. Right now and here, let us save a couple of code lines.

So the simplest and most persuasive blanket statement is OK to dissuade
people from poor choices.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: String Buffer

<f2418f34-c7af-49e9-901d-7621e1d224dan@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6364&group=comp.lang.ada#6364

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:28d0:: with SMTP id l16mr15155546qkp.500.1638492565170;
Thu, 02 Dec 2021 16:49:25 -0800 (PST)
X-Received: by 2002:a25:40cc:: with SMTP id n195mr18651142yba.305.1638492565018;
Thu, 02 Dec 2021 16:49:25 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 2 Dec 2021 16:49:24 -0800 (PST)
In-Reply-To: <sobepr$h88$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=92.40.193.184; posting-account=5K6RMgoAAADQeoHIOMi2dg5aYc0IVxGi
NNTP-Posting-Host: 92.40.193.184
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
<sob8df$vbj$1@dont-email.me> <sob9gf$5mh$1@gioia.aioe.org>
<sobcg4$tc4$1@dont-email.me> <sobepr$h88$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f2418f34-c7af-49e9-901d-7621e1d224dan@googlegroups.com>
Subject: Re: String Buffer
From: kevc3...@gmail.com (Kevin Chadwick)
Injection-Date: Fri, 03 Dec 2021 00:49:25 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 26
 by: Kevin Chadwick - Fri, 3 Dec 2021 00:49 UTC

> And note, that in most cases it is really thoughtless as the choice is
> made on the basis of how easy it is to declare a string component of a
> record type and then rewrite it.
>
> Later on throughout the rest of the program the user of Unbounded_String
> will be consistently punished for that poor choice because normal string
> operations are very uncomfortable with Unbounded_String. But that
> happens later. Right now and here, let us save a couple of code lines.
>
> So the simplest and most persuasive blanket statement is OK to dissuade
> people from poor choices.

I think I am glad that I am understanding this point about preferring strings early on in my Ada usage. Of course it is very easy to convert to a String as needed and whilst Randy mentioned yuck on "use" use, which I never use. I find package renames work well. I was thinking maybe you should never propagate an unbounded but then I am sure there will be the occasional scenario, where you expect the caller most likely wants to append and the code reads better without declares. As always...it depends..I guess?

With regard to a String buffer. It just occurred to me that the reason bounded is more efficient than unbounded is because, you could consider the bound max as a one time equivalent to strings.Builders grow(). In Go, I would try to only call grow, once anyway.

Re: String Buffer

<soc9p1$vpc$1@franka.jacob-sparre.dk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6366&group=comp.lang.ada#6366

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsfeed.xs3.de!callisto.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: String Buffer
Date: Thu, 2 Dec 2021 23:25:52 -0600
Organization: JSA Research & Innovation
Lines: 49
Message-ID: <soc9p1$vpc$1@franka.jacob-sparre.dk>
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com> <sob8df$vbj$1@dont-email.me> <sob9gf$5mh$1@gioia.aioe.org> <sobcg4$tc4$1@dont-email.me>
Injection-Date: Fri, 3 Dec 2021 05:25:53 -0000 (UTC)
Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226";
logging-data="32556"; mail-complaints-to="news@jacob-sparre.dk"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
 by: Randy Brukardt - Fri, 3 Dec 2021 05:25 UTC

"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message
news:sobcg4$tc4$1@dont-email.me...
> On 2021-12-02 21:15, Dmitry A. Kazakov wrote:
>>
>> It is true only to a certain degree. When comparing algorithms it is
>> valid to claim inefficiency without any context if computational
>> complexity sufficiently differs.
>>
>> For example, an O(N) algorithm is unquestionably inefficient comparing to
>> O(log N) one. I leave marginal cases of very small N.
>
> This is false. If you have the O(N) algorithm and it meets your
> requirements, then using it is more efficient than implementing the O(log
> N) algorithm. If you have both and the O(N) algorithm meets your
> requirements, the effort to get your data into a form where you can apply
> the O(log N) algorithm may still outweigh the time difference.
>
> As for "very small N", I have worked on systems where linear search was
> efficient for sequences of 100,000 items.

And it isn't unusual that you *are* working mostly with small N. Case in
point: The Janus/Ada parser table lookup routine. At one point, I tried to
speed it up by implementing a binary search algorithm. (The table is
logically a 2-dimensional array with the action being the element, but the
majority of the elements are error markers [which have no information]. The
usual storage is to omit those and store pairs of terminal/action. That's
many times smaller for a language like Ada.) The binary search seemed to
*slow down* parsing! I spent a week building instrumented versions, and
determined that the average number of pairs was about 8, and the binary
search (which necessarily was much more complex than a linear search) was
slower until the number of pairs was about 20. So it only helped the largest
states.

I ended up doing two other things instead: coding the lookup routine in
assembler, which got the lookup loop down to about 5 instructions (it might
be possible for a compiler to write that loop with fancy optimizations, but
I've never seen one that could, and Janus/Ada certainly isn't able), and
then I restructured the parse table to optimize lookups (terminals don't
appear with a uniform frequency in code). The net result was that average
lookup takes 1.6 iterations (of a 5 instruction loop); the binary version
(which executed a lot more code) took somewhere around 3.5 on average.

The point is, simpler can often be better (especially as it is more likely
to work the first time). And if it proves necessary to improve it, nothing
really substitutes for instrumenting the actual application.

Randy.

Re: String Buffer

<cf1181b6-4aaf-4056-8a46-67b9f8d7a99en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6367&group=comp.lang.ada#6367

  copy link   Newsgroups: comp.lang.ada
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: i2pn2.org!i2pn.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: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=46.147.99.152; posting-account=niG3UgoAAAD7iQ3takWjEn_gw6D9X3ww
NNTP-Posting-Host: 46.147.99.152
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cf1181b6-4aaf-4056-8a46-67b9f8d7a99en@googlegroups.com>
Subject: Re: String Buffer
From: vgodu...@gmail.com (Vadim Godunko)
Injection-Date: Fri, 03 Dec 2021 08:11:56 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Vadim Godunko - Fri, 3 Dec 2021 08:11 UTC

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.
>
> "https://groups.google.com/g/comp.lang.ada/c/NINmFln-YS4/m/5De5DeUAAAAJ"
>
> I thought bounded looked useful but then I realised that it allocates the max immediately anyway. It may be useful in constrained environments but then I do not use Strings in constrained environments.
>
> Unbounded is said to be inefficient because it re-allocates.
>
> In Go they have strings.Builder. I assume that is what Text_Buffer is aimed 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).
>
> Is Text_Buffer usable today with GCC 11?
>
> strings.Builder in Go behaves similarly to unbounded in that it doubles the 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-allocations.
>
> "https://pkg.go.dev/strings#Builder"
>
> If possible without breaking all of the string functions (length and separate capacity) and Unbounded Strings had a Grow function, then wouldn't that relieve the efficiency issue?
>
> In any case avoiding unbounded strings is almost certainly in the realm of 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 of 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 depends 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 Server 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. This 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.

Re: String Buffer

<nnd$55e87b4c$56b6bcf4@56f20470a9aa0149>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=6368&group=comp.lang.ada#6368

  copy link   Newsgroups: comp.lang.ada
Date: Fri, 3 Dec 2021 09:31:08 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2
Subject: Re: String Buffer
Content-Language: en-GB
Newsgroups: comp.lang.ada
References: <c80ebd43-1a92-4a05-a0db-7cb707191315n@googlegroups.com> <sob8df$vbj$1@dont-email.me>
From: bertus.d...@planet.nl (ldries46)
In-Reply-To: <sob8df$vbj$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$55e87b4c$56b6bcf4@56f20470a9aa0149>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!94.232.116.27.MISMATCH!abe005.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 38
Injection-Date: Fri, 03 Dec 2021 09:31:10 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: ldries46 - Fri, 3 Dec 2021 08:31 UTC

Op 2-12-2021 om 20:56 schreef Jeffrey R.Carter:
> On 2021-12-02 19:17, Kevin Chadwick wrote:
>>
>> Unbounded is said to be inefficient because it re-allocates.
>>
>> In any case avoiding unbounded strings is almost certainly in the
>> realm of premature optimisation
> "Efficiency" is only meaningful in the context of a project's
> quantitative timing requirements: an efficient implementation allows
> the project to meet those requirements, while an inefficient
> implementation does not.
>
> In the absence of such context, any claims of "inefficiency" (and
> especially blanket claims such as "Unbounded_String is inefficient")
> simply demonstrate the speaker's incompetence.
>
> For an example of context, a decade ago I worked on a soft-real-time
> system that made extensive use of Unbounded_String and had no problem
> meeting its timing requirements. Unbounded_String was clearly
> efficient for that project. Since most projects that would use
> Unbounded_String have even less restrictive timing requirements than
> that system, it seems likely that Unbounded_String will be efficient
> for them, too.
>
I don't like the word "Efficiency". because what doe it mean. In the
time that I started programming 1966/1967 computers were relative slow
and small. You did not like any kind of strings because they toke lots
of memory and lots of power. Gradually computers started to become
faster and bigger (in memory, smaller in size) that meant that string
operations also became faster and so use of string operations became
more normal. In my opinion programs that need a lot of string
manipulation do not need to be very fast because in general there the
output is the limiting factor. In most other programs string
manipulation is only a small part of the program still becoming faster
along with new developments. My statement is that string manipulation
does no have to become more efficient because other factors do limit the
efficciency of the program much more.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor