thoyt@DDN-WMS.ARPA (Thomas Hoyt) (05/30/89)
In issue #142, D. Papay is right on the $$$ with his comments on variable length strings. However... >...I suggest you remove the default expression " := 0" from your > record type ... and always declare ... with explicit discriminant > contraints... If you do this, you lose all the advantages of a parameterized record, i.e. variable length strings. Why not constrain the subtype of the range of the record parameter: ^^^^^ subtype Len_range is integer range 0..256; -- or some other max -- string length This way the compiler would know exactly how big the strings could ever get and plan accordingly...i.e. stop complaining. Of course, you could still have pretty huge strings without coming close to whatever Integer'Last is. Another advantage is that the writer of the generic could explicitly control how big the variable length strings could ever get, without having to rely upon implimentation details. You also eliminate a generic parameter, relieving the user of an unnecessary detail. Most text editing functions wouldn't ever need more than about 1024 chars at a time (need...hope?:-)) ****** Thomas Hoyt | "Government Computers for Government business..." CRC Systems, Inc. | "NO FUN ALLOWED..." thoyt@ddn-wms.arpa | "Oh no...it's written in COBOL..." ******
GDAU100@BGUVM.BITNET ("Jonathan B. Owen") (06/02/89)
In issue #143, Thomas Hoyt replied to my question about variable length strings. He is right by commenting that if the type V_string is used without the default of zero, your string is not of a variable length... Cliff baker replied to my question by saying he thinks the Verdix Ada is not smart enough to recognize the Max. size of the type by taking into consideration the upper limit of Len_range (and that the problem has nothing to do with the fact that the package is generic). Well, I disagree with this, as the Verdix Ada DOES recognize the max. size, IF THE UPPER LIMIT OF THE SUBTYPE IS CONSTANT, as in: subtype Len_range is integer range 0..132; I did not bother to mention my work-around to this problem. I defined a few non-generic packages to handle V_strings of length 15,80,132,512, 1024,2048. I had to replicate manually the body of these packages. Of course working this way is a compromise... The point is that the Verdix Ada works fine with these non-generic packages, in respect to the issue at hand. Baring the above in mind, I don't understand why the generic parameter Max_len should not be considered constant for the issue of determining the max. size. After all, it's value is avaliable during elaboration time, and of course cannot change, there after. Any thoughts? Jonathan ______________________________________________________________________________ (--) /--) /-(\ Email: gdau100@bguvm (bitnet) \ / /--K | \|/\ /\/) /|-\ Snail: 55 Hovevei Zion _/_/o /L__)_/o \/\__/ \X/ \_/ | |_/ Tel-Aviv, 63346 ISRAEL (/ Jonathan B. Owen Voice: (03) 281-422 Point of view: A chicken is the means by which an egg reproduces an egg. ______________________________________________________________________________
thoyt@DDN-WMS.ARPA (Thomas Hoyt) (06/02/89)
In Issue #143, Jonathon B. Owen writes... >... >Baring the above in mind, I don't understand why the generic parameter >Max_len should not be considered constant for the issue of determining >the max. size. After all, it's value is avaliable during elaboration >time, and of course cannot change, there after. From what I understand of your problem, it *is* a constant, just a constant that is too big for the compiler to handle. Max_Len is declared: generic Max_Len : Integer; Package (etc)... The string range statement thus defines the variable length string to be anywhere from 0 to Integer'Last. This raises the possiblity that Integer'Last length strings could be created on the fly. This frightening implication causes the anxiety from the compiler. Try this in your original generic. Put some constaints on the generic parameter: generic Max_Len : Integer range 0..20000 := 20000; Package (etc)... This does two things. It allows for a default max variable string length if you choose to pass in nothing for the parameter. It also tells the compiler that at most there will be 20000 char length strings created dynamically. This is a whole lot less than Integer'Last( normally around 2^32 or there abouts ) and will calm Verdix's nerves. Of course, you can adjust the constants accordingly. Also there may be implimentation limits on how big you can define dynamic objects at one time. As always, check your manuals. This ought to permit you to keep the generic solution, i.e. without hard coding string range limits into separate packages. (*Disclaimer* I do not *sigh* have access to a Verdix compiler...as always, if this patch should fail, the secretary will disavow all knowledge...etc...) ****** thoyt@ddn-wms.arpa | "Oh no...it's written in COBOL..." Thomas Hoyt | "Government Computers for Government business..." CRC Systems, Inc., Fairfax, VA -- 703-359-9400 | "NO FUN ALLOWED..." ******
GDAU100@BGUVM.BITNET ("Jonathan B. Owen") (06/04/89)
Thomas Hoyt writes that having the following: generic Max_len : Integer; package VSTR is subtype Len_range is integer range 0..Max_len; etc... DOES imply a maximum length for a discriminant of type Len_range, be it integer'LAST. Also, he suggests using a fixed upper limit to Max_len, say 20000. First, as far as I observed, on Vax Ada, the actuall value for Max_len for a particular instantiation is taken as the upper limit for a disc. of type Len_range. I see no reason why Verdix Ada should not do it. Secondly, I do believe defining the range of Max_len to be limited to 20000. Still, I think it would be unreasonable to allocate 20K for each V_string defined, when typicalalues for Max_len would be much smaller (say 15, 80 and such). It seems to me Verdix Ada handles Dynamically defined types/Subtypes differently than the Vax Ada. Come to think of it, I ran into a related problem as the above, in a non-generic package. Consider the following: type Record_header is record key : Key_type; time : Time_type; end record; Max_data_len : constant integer := 2048-Record_header'SIZE/8; subtype Data_len_range is integer range 0..Max_data_len; type Record_type( data_len : Data_len_range := 0 ) is record header : Record_header; data : String(1..data_len); end record; Say the Record_header occupies 48 bytes. The purpose of the above is to define a record which would occupy 2K at the most, including the header. The above works find on Vax-Ada but fails on Verdix with the same problem of not recognizing the upper limit of Data_len_range. I hope the shortcoming of Verix is now obvious... Jonathan ______________________________________________________________________________ (--) /--) /-(\ Email: gdau100@bguvm (bitnet) \ / /--K | \|/\ /\/) /|-\ Snail: 55 Hovevei Zion _/_/o /L__)_/o \/\__/ \X/ \_/ | |_/ Tel-Aviv, 63346 ISRAEL (/ Jonathan B. Owen Voice: (03) 281-422 Point of view: A chicken is the means by which an egg reproduces an egg. ______________________________________________________________________________
pfw@aber-cs.UUCP (Paul Warren) (06/06/89)
In article <8906012020.AA03083@ajpo.sei.cmu.edu>, GDAU100@BGUVM.BITNET ("Jonathan B. Owen") writes: > In issue #143, Thomas Hoyt replied to my question about variable length > strings. He is right by commenting that if the type V_string is used > without the default of zero, your string is not of a variable length... > I used to use the V_STRING package quite a lot (using the Alsys compiler) and discovered that it was none too fast. I tried a Grady Booch package for the same job and got a speed-up factor of 40. I never tried these two components on VADS though. -- Paul Warren, tel +44 970 623111 x3068 Computer Science Department, pfw%cs.aber.ac.uk@uunet.uu.net (ARPA) University College of Wales, pfw@uk.ac.aber.cs (JANET) Aberystwyth, Dyfed, United Kingdom. SY23 3BZ.