From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Better way to fill Storage_IO? Date: Mon, 17 May 2021 20:14:36 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:KcWswe0cAKnhjwOwbVKAk0GBTgM= Xref: reader02.eternal-september.org comp.lang.ada:61999 List-Id: Michael Hardeman writes: > So I've been messing around with the new Ada 2020 package > Ada.Streams.Storage.Bounded/Unbounded; and if I'm understand it > correctly it allows you to treat your program's memory like a stream > without having to open file descriptors (which should make it > faster?). That seems like a powerful abstraction to me and a great > addition to the language. This would be my version: with Ada.Text_IO; use Ada.Text_IO; with Ada.Streams.Storage.Unbounded; procedure Test is Test : constant String := "040b2cec765b4bbbdb29d83b6dcaf776"; Test_Stream : aliased Ada.Streams.Storage.Unbounded.Stream_Type; begin String'Output (Test_Stream'Access, Test); declare S : constant String := String'Input (Test_Stream'Access); begin Put_Line (S); end; end Test; 'Output writes the discriminants of the object, if any, then the object; 'Input uses them to reconstruct the object, so in this case that means the bounds, and hence the length. > I was wondering if we could find a better way to fill the stream other > than writing the variables into it? Can anyone figure out a good way > to just stream a variable's bytes directly? This *is* the way to just stream the variable's bytes directly. What sort of syntax were you hoping for?