From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,15e41875b75969fc X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Dynamically reallocated buffer Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1180679626.254857.59070@w5g2000hsg.googlegroups.com> Date: Fri, 1 Jun 2007 09:30:04 +0200 Message-ID: NNTP-Posting-Date: 01 Jun 2007 09:27:45 CEST NNTP-Posting-Host: 535c3f1e.newsspool4.arcor-online.net X-Trace: DXC=8g\;o3mE@]DFJ3]dH>I?oE4IUKkgBDM]5>k2knAI X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:16015 Date: 2007-06-01T09:27:45+02:00 List-Id: On Thu, 31 May 2007 23:33:46 -0700, Maciej Sobczak wrote: > I need a dynamically reallocated buffer of bytes, which I can extend > at run-time by appending new fragments to the whole buffer. The > purpose of the buffer is to pass it later to the subprogram that > writes it "en bloc" to some external device. > > For those of you who know C++ I need something like: > > vector buffer; > // fill the buffer with push_back or insert at end > // ... > write_to_device(&buffer[0], buffer.size()); > > The problem is that Ada.Containers.Vectors does not provide the > necessary guarantees to be any useful in this context. > > What are your suggestions? type Device_Buffer is array (Positiver range <>) of Interfaces.C.unsigned_char; The maximal block size is usually known. If not, then device is stream-oriented and blocks can be safely split into chucks of known size. In that case Device_Buffer is a segmented buffer. In most cases you don't need to realloc anything. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de