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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-18 03:00:26 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!dialin-145-254-042-049.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Counter-proposal for variable arrays Date: Sat, 18 Oct 2003 12:05:46 +0200 Organization: At home Message-ID: References: <1065215180.95094@master.nyc.kbcfp.com> <19p2ovk1jh4krn2h5cql44p37ovf6va99i@4ax.com> <4pe7ov0gsepk8p8cq88ropvq4sookdhatk@4ax.com> <1065635640.270857@master.nyc.kbcfp.com> <725aovsqh10dv5p5nh1e7k2qvjjcqustsa@4ax.com> <1065709998.992831@master.nyc.kbcfp.com> <7aisov0u9cha33e1fgvpli7mmdqqmmh7l9@4ax.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-042-049.arcor-ip.net (145.254.42.49) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1066471225 26671368 145.254.42.49 (16 [77047]) User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:1115 Date: 2003-10-18T12:05:46+02:00 List-Id: Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:7aisov0u9cha33e1fgvpli7mmdqqmmh7l9@4ax.com... >> On Wed, 15 Oct 2003 19:52:22 -0500, "Randy Brukardt" >> wrote: >> >> >"Hyman Rosen" wrote in message >> >news:1065709998.992831@master.nyc.kbcfp.com... >> >> Dmitry A. Kazakov wrote: >> >> > It is already so. Consider: >> >> > type Tricky (I, J : Positive) is record >> >> > X : String (1..I); >> >> > Y : String (1..J); >> >> > end record; >> >> > The offset to Y is variable and depends on the value of I. >> >> >> >> I Didn't Know You Could Do That In Ada(tm). :-) >> >> It really works that way? And you can have procedures >> >> which just take unconstrained Tricky parameters, and >> >> they'll know how to deal with all instances? Cool! >> > >> >You can write this, but it often isn't implemented with variable >> >offsets. What Janus/Ada does is to use discontinous storage for >> >depends-on-discriminant components. The component itself is a >> >descriptor, and has fixed size. The array data is allocated separately. >> >That way, we > can >> >actually change the data memory when the discriminants are changed by >> >assignment, and we don't use more memory than necessary. >> >> An interesting approach. But what will happen if I write: >> >> type Tricky_Ptr is access Tricky; >> for Tricky_Ptr'Storage_Pool use My_Stack_Pool; >> >> Do you switch between representations? > > Huh? We just use whatever pool is the correct one. So either (1) the array data is in effect allocated not in My_Stack_Pool, but in the heap, or else, (2) you break My_Stack_Pool by calling Deallocate on array data out of order, when the object gets resized. > To expand on that: For record types, we declare a number of subprograms > with the type (unless it is very simple). One of those is the allocation > subprogram; it takes the object address and a storage pool parameter. This > routine is called whenever an object is constructed (even on the stack); > of course, there is a pool for memory which is recovered when the stack > frame is destroyed. (Tuck has convinced me that our implementation is > subtly wrong; it will need major surgury, but the basic idea will be > remain the same. The main change will be that every stack frame will > (logically) have its own pool - currently, there is one global stack > pool.) So the first variant. It would be very interesting to try some time to expose such things for user as it was finally made with user-defined storage pools. I mean discontinuously allocated objects without pointers. Recursive types, infinite types, ragged arrays all that stuff ... -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de