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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2f343e3986ead102 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: String declaration and initialization References: <05bce551-cd98-417c-8664-847b29124c19@l64g2000hse.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1211486493 12.201.97.213 (Thu, 22 May 2008 20:01:33 GMT) NNTP-Posting-Date: Thu, 22 May 2008 20:01:33 GMT Organization: AT&T ASP.att.net Date: Thu, 22 May 2008 20:01:33 GMT Xref: g2news1.google.com comp.lang.ada:297 Date: 2008-05-22T20:01:33+00:00 List-Id: S�bastien wrote: > > So I don't actually know how fast is the conversion between String and > Unbounded_String but I think it's a waste of ressource. You've already wasted quite a bit of your most expensive resource, a developer's time, worrying about this. Far more efficient is to do it the obvious way, with Unbounded_String, and only worry about the time of the conversions if you are unable to meet your timing requirements. > But you give me an Idea : > declare > buffer: access String; > Free_String is new Unchecked_Deallocation(String, access all String); > begin > case SomeTest is > case TEST1 => > buffer := new String("Test1"); > case TEST2 => > buffer := new String("Test2"); > end case; > MyTreatment1(buffer.all, buffer.all'Size); > MyTreatment2(buffer.all, buffer.all'Size); > MyTreatment3(buffer.all, buffer.all'Size); > end; > > but it doesn't work of course since I can't create with new an > unconstrained object. You can if you get the syntax right, as has been pointed out elsewhere. But this is probably your worst choice. Here you have written a memory leak. You should avoid explicit access values whenever possible, since such errors are so easy to make. -- Jeff Carter "You a big nose have it." Never Give a Sucker an Even Break 107