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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1bad3dcf22d5a071 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Generics and parameter modes Date: 1999/08/17 Message-ID: <37b9a5e3@news1.us.ibm.net>#1/1 X-Deja-AN: 513880143 Content-transfer-encoding: 7bit References: <37B85F88.C87638C4@dowie-cs.demon.co.uk> X-Trace: 17 Aug 1999 18:11:47 GMT, 32.101.8.24 Organization: Global Network Services - Remote Access Mail & News Services X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset="US-ASCII" Mime-version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: postmaster@ibm.net Date: 1999-08-17T00:00:00+00:00 List-Id: In article <37B85F88.C87638C4@dowie-cs.demon.co.uk> , Martin Dowie wrote: > i have an instance of a package similar to the generic listed below. > when calling the 'size' routine the actual parameter is passed by copy > and not by reference as i had expected. this is really annoying as the > data object is a few hundred kbytes in size! is there anything in Ada95 > that allows/requires this? > > generic > type an_item is private; > maximum_number_of_items : positive; > package generic_list is > subtype a_number_of_items is natural range 0 .. > maximum_number_of_items; > subtype an_item_index is natural range 1 .. maximum_number_of_items; > > type a_list is private; > -- Lots of other stuff... > function size (list : in a_list) return a_number_of_items; > private > type an_array_of_items is array (an_item_index) of an_item; > type a_list is record > current_size, current_item : a_number_of_items; > items : an_array_of_items; > end record; > end generic_list; > > the type used in the declaration ... Do you mean "in the instantiation"? > ...is a variant record which it self > contains variant fields within a number of the variant branches (approx. > 300 bytes storage required). o You could make the list type limited, and implement the full view of the type as limited: type A_List is limited private; ... private ... type A_List is limited record ... end record; You lose the assignment operator, but that's no big deal. Just declare a Copy operation: procedure Copy (From : in A_List; To : in out A_List); o You can privately implement the type as tagged. Tagged types are always passed by reference: type A_List is private; ... private ... type A_List is tagged record ... end record; -- Matt It is impossible to feel great confidence in a negative theory which has always rested its main support on the weak points of its opponent. Joseph Needham, "A Mechanistic Criticism of Vitalism"