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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5a817e6528505e97 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1993-02-26 11:02:55 PST Newsgroups: comp.lang.ada Path: sparky!uunet!gatekeeper.us.oracle.com!sgiblab!darwin.sura.net!seas.gwu.edu!mfeldman From: mfeldman@seas.gwu.edu (Michael Feldman) Subject: Re: generic queue packages Message-ID: <1993Feb26.190255.24811@seas.gwu.edu> Sender: news@seas.gwu.edu Organization: George Washington University References: <1993Feb24.212641.8326@evb.com> <1993Feb26.031650.3447@leeweyr.sccsi.com> Date: Fri, 26 Feb 1993 19:02:55 GMT Date: 1993-02-26T19:02:55+00:00 List-Id: In article <1993Feb26.031650.3447@leeweyr.sccsi.com> bill@leeweyr.sccsi.com (Bill Lee) writes: >In article <1993Feb24.212641.8326@evb.com> jgg@evb.com (John Goodsen) writes: >>wallace@cookie.enet.dec.com (Richard Wallace) writes: >> >>>Remember that a variant record will have the maximum size elements used when >>>allocating the memory for the elements in your queue. >>> >> >>Not true. It is implementation dependent. An implmentation >>*may* choose to use run-time logic and allocate the proper >>size based upon the variant. >> >>Doesn't DEC Ada do just this ??? > >Yes. > So does much-maligned Meridian. Folks, what we have here is a classical time-space tradeoff. You can't have it both ways. Either allocate the space statically, for the maximum size, or do it dynamically and re-allocate every time the size changes. (Or allocate in blocks, which is a compromise between the two.) This is almost an FAQ. The most intelligent way to deal with variant records is to make sure that the discriminant has a reasonable type. TYPE Stupid (Length: Positive := 8) IS RECORD String_Part: String(1..Length); END RECORD; is a recipe for big trouble. Yet I see it a lot, and not just in old textbooks. Surely the writer didn't REALLY mean that the string might possibly be Positive'Last characters long, right? Basically the writer was too lazy to define a subtype that revealed the realistic maximum length - 64 maybe, 255, but surely not Positive'Last. That's 32767 even if Integer is 16 bits. SUBTYPE Realistic IS Integer RANGE 1..64; -- for example TYPE Smart (Length: Realistic := 8) IS RECORD String_Part: String(1..Length); END RECORD; will waste at most 64 characters' worth, whether the compiler chooses static or dynamic allocation. That's a whole lot better than the roughly 2 gigabytes you'd try to allocate for a record of the first type, if the compiler used static allocation and Integer was 32 bits. (TeleSoft and Verdix do this, for example.) So it's (more) portable. Variant records are a GREAT way to test intelligent design decisions. Don't blame bad ones on the language or the compiler, friends. Mike Feldman ------------------------------------------------------------------------ Michael B. Feldman co-chair, SIGAda Education Committee Professor, Dept. of Electrical Engineering and Computer Science School of Engineering and Applied Science The George Washington University Washington, DC 20052 USA (202) 994-5253 (voice) (202) 994-5296 (fax) mfeldman@seas.gwu.edu (Internet) "The most important thing is to be sincere, and once you've learned how to fake that, you've got it made." -- old show-business adage ------------------------------------------------------------------------