Login  Register

Passed by references and by value

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Passed by references and by value

nacho
238 posts
Hi,
In PBE says that ordinary objects' ivars are passed by references and small integers are passed by value.
Is there a way to know if a class is passed by reference or by value?
Only small integers are passed as value?
Thanks in advance
Nacho

Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Mark Rizun
194 posts
Hi,

Most classes are passed by reference including those that were defined by user.
But classes like integer are passed by value.
I think it's similar to C#.
I may be wrong, so better wait for another more competent reply:)

Best,
Mark

2014-09-25 21:14 GMT+03:00 nacho <[hidden email]>:
Hi,
In PBE says that ordinary objects' ivars are passed by references and small
integers are passed by value.
Is there a way to know if a class is passed by reference or by value?
Only small integers are passed as value?
Thanks in advance
Nacho





-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Passed-by-references-and-by-value-tp4780289.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Esteban A. Maringolo
2343 posts
In reply to this post by nacho
2014-09-25 15:14 GMT-03:00 nacho <[hidden email]>:
> Hi,
> In PBE says that ordinary objects' ivars are passed by references and small
> integers are passed by value.
> Is there a way to know if a class is passed by reference or by value?

> Only small integers are passed as value?

Yes.

It has to do with the object headers, SmallIntegers are embedded in the OH.


Esteban A. Maringolo

Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Mark Rizun
194 posts
> Only small integers are passed as value?

Yes.

It has to do with the object headers, SmallIntegers are embedded in the OH.

What about Float, for example? 

Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

abergel
5677 posts
Floats are passed as values.
Objects that are passed as values should be immutable, as floats and integers.

Alexandre
-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



On Sep 25, 2014, at 3:35 PM, Mark Rizun <[hidden email]> wrote:

> Only small integers are passed as value?

Yes.

It has to do with the object headers, SmallIntegers are embedded in the OH.

What about Float, for example? 


Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Esteban A. Maringolo
2343 posts
In reply to this post by Mark Rizun
I forgot. Floats too.

And I think that's it.



Esteban A. Maringolo


2014-09-25 15:35 GMT-03:00 Mark Rizun <[hidden email]>:

>> > Only small integers are passed as value?
>>
>> Yes.
>>
>> It has to do with the object headers, SmallIntegers are embedded in the
>> OH.
>
>
> What about Float, for example?
>

Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

stepharo
5159 posts
In reply to this post by nacho

> Hi,
> In PBE says that ordinary objects' ivars are passed by references and small
> integers are passed by value.

Strange I do not remember having written that.
Especially because in Smalltalk this has no real interest.

> Is there a way to know if a class is passed by reference or by value?
In Smalltalk consider that everything is an object and that you pass a
reference to the object.

> Only small integers are passed as value?
> Thanks in advance
> Nacho
>
>
>
>
>
> -----
> Nacho
> Smalltalker apprentice.
> Buenos Aires, Argentina.
> --
> View this message in context: http://forum.world.st/Passed-by-references-and-by-value-tp4780289.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

nacho
238 posts
This post was updated on Sep 25, 2014; 7:56pm.
"
stepharo wrote
> Hi,
> In PBE says that ordinary objects' ivars are passed by references and small
> integers are passed by value.

Strange I do not remember having written that.
Especially because in Smalltalk this has no real interest.
Well you also wrote that :p

"Deep in the implementation of Smalltalk, there are three different kinds of objects. There are (1) ordinary objects with instance variables that are passed by references, there are (2) small integers that are passed by value, and there are (3) indexable objects like arrays that hold a contiguous portion of memory. The beauty of Smalltalk is that you normally don’t need to care about the differences between these three kinds of object."

> Is there a way to know if a class is passed by reference or by value?
In Smalltalk consider that everything is an object and that you pass a
reference to the object.
> Only small integers are passed as value?
> Thanks in advance
> Nacho
>
>
>
>
>
> -----
> Nacho
> Smalltalker apprentice.
> Buenos Aires, Argentina.
> --
> View this message in context: http://forum.world.st/Passed-by-references-and-by-value-tp4780289.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>
Nacho Smalltalker apprentice. Buenos Aires, Argentina.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Clément Béra
1053 posts
Depending on the VM you use, different objects are passed by values.

Currently -> only smallintegers
on Spur 32 bits VM -> smallintegers and characters
on Spur 64 bits VM -> smallintegers, characters and smallfloat

But as Stef said it does not really matter in smalltalk. 

2014-09-25 21:55 GMT+02:00 nacho <[hidden email]>:
"
stepharo wrote
>> Hi,
>> In PBE says that ordinary objects' ivars are passed by references and
>> small
>> integers are passed by value.
>
> Strange I do not remember having written that.
> Especially because in Smalltalk this has no real interest.
>
>
> Well you also wrote that :p
>
> "Deep in the implementation of Smalltalk, there are three different kinds
> of objects. There are (1) ordinary objects with instance variables that
> are passed by references, there are (2) small integers that are passed by
> value, and there are (3) indexable objects like arrays that hold a
> contiguous portion of memory. The beauty of Smalltalk is that you normally
> don’t need to care about the differences between these three kinds of
> object.
>
>> Is there a way to know if a class is passed by reference or by value?
> In Smalltalk consider that everything is an object and that you pass a
> reference to the object.
>> Only small integers are passed as value?
>> Thanks in advance
>> Nacho
>>
>>
>>
>>
>>
>> -----
>> Nacho
>> Smalltalker apprentice.
>> Buenos Aires, Argentina.
>> --
>> View this message in context:
>> http://forum.world.st/Passed-by-references-and-by-value-tp4780289.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>>





-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Passed-by-references-and-by-value-tp4780289p4780321.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Marcus Denker-4
7582 posts

On 26 Sep 2014, at 08:07, Clément Bera <[hidden email]> wrote:

> Depending on the VM you use, different objects are passed by values.
>
> Currently -> only smallintegers
> on Spur 32 bits VM -> smallintegers and characters
> on Spur 64 bits VM -> smallintegers, characters and smallfloat
>
> But as Stef said it does not really matter in smalltalk.
>

Yes, even for these cases you pass the *reference*, only that the reference
happens to encode the value.

        Marcus


signature.asc (210 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Marcus Denker-4
7582 posts
In reply to this post by Esteban A. Maringolo

On 25 Sep 2014, at 20:28, Esteban A. Maringolo <[hidden email]> wrote:

> 2014-09-25 15:14 GMT-03:00 nacho <[hidden email]>:
>> Hi,
>> In PBE says that ordinary objects' ivars are passed by references and small
>> integers are passed by value.
>> Is there a way to know if a class is passed by reference or by value?
>
>> Only small integers are passed as value?
>
> Yes.
>
> It has to do with the object headers, SmallIntegers are embedded in the OH.
>
In the *reference*, not the header. The reference points to a header for a normal
object, for small-integers the reference *is* the integer value. This means that
there is no header for the integers.

        Marcus

signature.asc (210 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

Henrik Sperre Johansen
1774 posts

On 26 Sep 2014, at 8:24 , Marcus Denker <[hidden email]> wrote:

>
> On 25 Sep 2014, at 20:28, Esteban A. Maringolo <[hidden email]> wrote:
>
>> 2014-09-25 15:14 GMT-03:00 nacho <[hidden email]>:
>>> Hi,
>>> In PBE says that ordinary objects' ivars are passed by references and small
>>> integers are passed by value.
>>> Is there a way to know if a class is passed by reference or by value?
>>
>>> Only small integers are passed as value?
>>
>> Yes.
>>
>> It has to do with the object headers, SmallIntegers are embedded in the OH.
>>
>
> In the *reference*, not the header. The reference points to a header for a normal
> object, for small-integers the reference *is* the integer value. This means that
> there is no header for the integers.
>
> Marcus
So, a succinct phrasing indifferent to object format, using a relatively well-defined term, would be:
Only immediate objects are passed by value.

(Which means you have to explain immediate objects, as markus did)

Cheers,
Henry

signature.asc (859 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Passed by references and by value

abergel
5677 posts
In reply to this post by stepharo
Indeed, one should not care about copy by value / reference in Pharo.

Alexandre
-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



On Sep 25, 2014, at 4:52 PM, stepharo <[hidden email]> wrote:


Hi,
In PBE says that ordinary objects' ivars are passed by references and small
integers are passed by value.

Strange I do not remember having written that.
Especially because in Smalltalk this has no real interest.

Is there a way to know if a class is passed by reference or by value?
In Smalltalk consider that everything is an object and that you pass a reference to the object.
Only small integers are passed as value?
Thanks in advance
Nacho





-----
Nacho
Smalltalker apprentice.
Buenos Aires, Argentina.
--
View this message in context: http://forum.world.st/Passed-by-references-and-by-value-tp4780289.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.