octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #59500] sub-classes of octave_base_value aren'


From: anonymous
Subject: [Octave-bug-tracker] [bug #59500] sub-classes of octave_base_value aren't assignable
Date: Thu, 26 Nov 2020 00:27:46 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:68.9) Gecko/20100101 Goanna/4.6 Firefox/68.9 Mypal/28.14.2

Follow-up Comment #6, bug #59500 (project octave):

An assignment operator is needed to allow copying the data contents of an
object and disallow copying the reference count. The proposed assignment
operator for octave_base_value in comment #3 does that. Setting the assignment
operator of octave_base_value to default won't compile because it tries to
assign to the 'refcount' that isn't by definition assignable.
 
 One may argue that if someone defines 'myfunction' as:
 

 octave_value_list
myfunction (const octave_value_list& lst, int n = 0)
{
  static octave_value val = args(0);
  return ovl ();
}


ans uses  `*static_cast<octave_scalar*> (lst(0).internal_rep ()) = double(i);`
it leads to an unwanted result and in the next iterations the static variable
is changed. One can prevent such behavior by defining a second octave_value:
 

octave_value_list lst = ovl (octave_value (0.0));

octave_value tmp(0.0);

for (int i = 0; i < 1000000; i++)
  {
    *static_cast<octave_scalar*> (tmp.internal_rep ()) = double(i);
    
    lst(0) = tmp;
    
    myfunction (lst);
  }


Another solution is checking the reference count:


octave_value_list lst = ovl (octave_value (0.0));

for (int i = 0; i < 1000000; i++)
  {
    if (lst(0).get_count () > 1)
      lst(0) = double(i);
    else
      *static_cast<octave_scalar*> (lst(0).internal_rep ()) = double(i);
      
    myfunction (lst);
  }


However if the decision is keeping the current behavior I suggest to make
octave_value behave faster for lightweight objects (possibly embedding small
objects directly in octave_value). If it is OK I may upload a patch that
implements such structure. This strategy may be extended to small arrays and
lists.

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?59500>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]