Re: Pass by Reference

new topic     » goto parent     » topic index » view thread      » older message » newer message
jaygade said...

To be clear, Euphoria DOES pass by reference but it copies on write. So there is a performance advantage there.

Agreed. Right now, this is just an implementation detail, done for speed. (Unless there are bugs) the effect is to emulate pass by value. It's functionally the same, but faster.

As far as the user is concerned, it's pass by value - just a faster pass by value.

But, since we are already doing pass by reference behind the scenes, how much harder would it be to do expore true pass by reference to the users of the language?

Spock said...

Question:

For every write (eg, x[i] = n) does the internal routine check to see if "x" has a refcount [and if it has make a fresh copy] before setting the data?

Spock

I believe so, yes. Fortunately, the check a very quick operation - read one int (the refcount) and only if it's not equal to one, then make a fresh copy.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu