* Generics and parameter modes @ 1999-08-16 0:00 Martin Dowie 1999-08-17 0:00 ` Tucker Taft 1999-08-17 0:00 ` Matthew Heaney 0 siblings, 2 replies; 6+ messages in thread From: Martin Dowie @ 1999-08-16 0:00 UTC (permalink / raw) 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 is a variant record which it self contains variant fields within a number of the variant branches (approx. 300 bytes storage required). i'm using Rational Apex v3 and have tried a mini version at home (using the above) and ObjectAda seems to pass it by reference (not 100% on this as my Intel assembler knowledge is zilch!). ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Generics and parameter modes 1999-08-16 0:00 Generics and parameter modes Martin Dowie @ 1999-08-17 0:00 ` Tucker Taft 1999-08-21 0:00 ` Martin Dowie 1999-08-17 0:00 ` Matthew Heaney 1 sibling, 1 reply; 6+ messages in thread From: Tucker Taft @ 1999-08-17 0:00 UTC (permalink / raw) 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? Non-limited, non-tagged record types may be passed either by reference or by copy. On the other hand, I am quite surprised that a compiler would go out of its way to pass such a large object by copy, since it requires more work. The only reasons I can imagine for doing this are: 1) the compiler is trying to enable more generic code sharing (but that seems a bit far-fetched, since even in a shared generic it "knows" a_list is a record type); 2) there is some kind of alignment problem, where the actual parameter is not properly aligned for the code inside the generic (again a bit far-fetched); 3) the actual parameter is marked volatile or atomic (see RM95 C.6(19)); 4) convention C_Pass_By_Copy applies to the type (I don't see such a pragma below); 5) the compiler has a bug ;-). Are you really sure that it is passing the parameter by copy? I would contact Rational and file a lousy-code-quality-but-not-quite-a-bug report. > 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 is a variant record which it self > contains variant fields within a number of the variant branches (approx. > 300 bytes storage required). > > i'm using Rational Apex v3 and have tried a mini version at home (using > the above) and ObjectAda seems to pass it by reference (not 100% on this > as my Intel assembler knowledge is zilch!). ObjectAda would pass such an object by reference unless the actual were misaligned (maladjusted? ;-), marked atomic or volatile, or had a C_Pass_By_Copy convention. -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Generics and parameter modes 1999-08-17 0:00 ` Tucker Taft @ 1999-08-21 0:00 ` Martin Dowie 1999-08-21 0:00 ` Robert Dewar 0 siblings, 1 reply; 6+ messages in thread From: Martin Dowie @ 1999-08-21 0:00 UTC (permalink / raw) well, if this helps, i've now discovered that the object being passed was a component of a record, but if i do a rename of that component use that in the call, it changes to a by-reference! what do you suspect now?! (thanks for your help & matthew!) Tucker Taft wrote: > 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? > > Non-limited, non-tagged record types may be passed either by reference > or by copy. On the other hand, I am quite surprised that a compiler > would go out of its way to pass such a large object by copy, since it > requires more work. The only reasons I can imagine for doing this are: > > 1) the compiler is trying to enable more generic code sharing > (but that seems a bit far-fetched, since even in a shared > generic it "knows" a_list is a record type); > 2) there is some kind of alignment problem, where the actual parameter > is not properly aligned for the code inside the generic (again > a bit far-fetched); > 3) the actual parameter is marked volatile or atomic (see RM95 C.6(19)); > 4) convention C_Pass_By_Copy applies to the type (I don't see such > a pragma below); > 5) the compiler has a bug ;-). > > Are you really sure that it is passing the parameter by copy? I would > contact Rational and file a lousy-code-quality-but-not-quite-a-bug report. > > > 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 is a variant record which it self > > contains variant fields within a number of the variant branches (approx. > > 300 bytes storage required). > > > > i'm using Rational Apex v3 and have tried a mini version at home (using > > the above) and ObjectAda seems to pass it by reference (not 100% on this > > as my Intel assembler knowledge is zilch!). > > ObjectAda would pass such an object by reference unless the actual > were misaligned (maladjusted? ;-), marked atomic or volatile, or had > a C_Pass_By_Copy convention. > > -- > -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ > Technical Director, Distributed IT Solutions (www.averstar.com/tools) > AverStar (formerly Intermetrics, Inc.) Burlington, MA USA ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Generics and parameter modes 1999-08-21 0:00 ` Martin Dowie @ 1999-08-21 0:00 ` Robert Dewar 1999-08-21 0:00 ` Martin Dowie 0 siblings, 1 reply; 6+ messages in thread From: Robert Dewar @ 1999-08-21 0:00 UTC (permalink / raw) Tucker said > > ObjectAda would pass such an object by reference unless the > > actual > > were misaligned (maladjusted? ;-), marked atomic or > > volatile, or had > > a C_Pass_By_Copy convention. As would GNAT, indeed it is hard to imagine any other sensible implementation choice! Robert Dewar Ada Core Technologies Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Generics and parameter modes 1999-08-21 0:00 ` Robert Dewar @ 1999-08-21 0:00 ` Martin Dowie 0 siblings, 0 replies; 6+ messages in thread From: Martin Dowie @ 1999-08-21 0:00 UTC (permalink / raw) sensible - yes is it happening - no :-( Robert Dewar wrote: > Tucker said > > > > ObjectAda would pass such an object by reference unless the > > > actual > > > were misaligned (maladjusted? ;-), marked atomic or > > > volatile, or had > > > a C_Pass_By_Copy convention. > > As would GNAT, indeed it is hard to imagine any other sensible > implementation choice! > > Robert Dewar > Ada Core Technologies > > Sent via Deja.com http://www.deja.com/ > Share what you know. Learn what you don't. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Generics and parameter modes 1999-08-16 0:00 Generics and parameter modes Martin Dowie 1999-08-17 0:00 ` Tucker Taft @ 1999-08-17 0:00 ` Matthew Heaney 1 sibling, 0 replies; 6+ messages in thread From: Matthew Heaney @ 1999-08-17 0:00 UTC (permalink / raw) In article <37B85F88.C87638C4@dowie-cs.demon.co.uk> , Martin Dowie <martin@dowie-cs.demon.co.uk> 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" ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1999-08-21 0:00 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1999-08-16 0:00 Generics and parameter modes Martin Dowie 1999-08-17 0:00 ` Tucker Taft 1999-08-21 0:00 ` Martin Dowie 1999-08-21 0:00 ` Robert Dewar 1999-08-21 0:00 ` Martin Dowie 1999-08-17 0:00 ` Matthew Heaney
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox