can someone tell me what is the difference between coping one transaction(item) to the another like in examples bellow ( add_method_port_1 and add_method_port_2 ):
add_method_port_1 (added_item: item_s) is {
var new_item: new_item_s;
gen new_item keeping {
it.my_trans_s == added_item.as_a(t_trans_s);
};
};
add_method_port_2 (added_item: item_s) is {
var new_item : new_item_s = deep_copy(added_item.as_a(t_trans_s));
};
Where new_item_s looks like:
struct new_item_s like item_s {
%my_trans_s: t_trans_s;
};
Thanks, Andrija
In this specific example, assuming that new_item_s has only one field my_trans_s, there is no difference in outcome.
In practice, the meaning and the goal of "gen keeping" and deep_copy is quite different:
In other words, if the assumption "new_item_s has only one field my_trans_s" is wrong, the result are going to be very much different.
Actually, the results of the two methods are different even if the assumption mentioned in Rodion's answer does hold.
With the first method, new_item
points to the same my_trans_s
object as the original added_item
, because the constraint it.my_trans_s == added_item.as_a(t_trans_s)
means pointer equality.
With the second method, new_item
points to a copy of the original my_trans_s
, because deep_copy
copies everything recursively.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.