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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e6c9800e35ccfeee X-Google-Attributes: gid103376,public From: Samuel Mize Subject: Re: GNAT: Performance of String functions Date: 1997/07/23 Message-ID: <33D66563.3F86@link.com>#1/1 X-Deja-AN: 258395046 References: <5r1l6e$e0h$1@ratatosk.uio.no> <1997Jul22.071638.1@eisner> <33D4F30F.5299@online.no> <5r5cfh$irn$1@ratatosk.uio.no> Organization: Hughes Training Inc. Reply-To: smize@link.com Newsgroups: comp.lang.ada Date: 1997-07-23T00:00:00+00:00 List-Id: Tarjei Jensen wrote: > I'd be delighted if it is possible to write a portable bounded > string package > that does not copy blindly on assignment. Here's what I understand you want: 1 Each string has its own individual maximum length, and a currently-used length. 2 Each string allocates ONLY its maximum length, not a max length for all strings of this subtype. 3 The user can assign A to B so long as the "used" length of A is less than the maximum length of B. 4 Normal assignment is available. 5 Unused bytes are not copied on assignment. You can build a type to do what you want (except you have to use a "copy" procedure), but Bounded_Type doesn't quite do what you want. You can get all but 4 (normal assignment) with a limited variant record with a discriminant (max length). To assign the value, you provide a "copy" routine. Don't provide a default value for the discriminant, so the user will have to explicitly give a max size for each variable of this type. (If you provide a default value, the implementation may allocate the subtype's max size for each record.) Since Ada's "user-defined" assignment is actually user code adjusting and finalizing values, you can't get 4 (unused bytes not copied) with normal assignment. (You might get it by using a variant record, but then the compiler can allocate the subtype's max size for each record.) Sam Mize