Finding the instance reference of an object

Aaron Brady castironpi at gmail.com
Tue Oct 28 22:43:29 CET 2008


On Oct 27, 2:11 pm, Joe Strout <j... at strout.net> wrote:
> On Oct 27, 2008, at 12:19 PM, goobe... at gmail.com wrote:
>
> > I think this "uncontrived" example addresses the C/Python difference
> > fairly directly (both were tested):
>
> That's correct, but of course, C is a decades-old language barely a  
> step above assembler.  For a fair comparison, pick any modern OOP  
> language, including the C derivatives (C++, Objective-C, Java), and  
> compare a Python object to an object in that language, rather than to  
> a struct.
>
> > In Python, variables are just names/aliases for *references* to
> > objects, not names for the objects/values themselves. The variable
> > names themselves do not correspond directly to the objects' memory
> > locations.
>
> Exactly!  In C++, this would be like a pointer variable.  In Java, RB,  
> or .NET, it's like an object reference.
>
> > While yes, technically, it is true that those reference
> > values must be stored somewhere in memory, *that* is the
> > implementation detail.
>
> Agreed.  (And this was my point in response to someone arguing that no  
> such location exists.)
>
> > But is is not the *locations* of these
> > references (i.e., the locations of the Python *variables*) that are
> > copied around, it is the references themselves (the locations of the
> > Python *objects*) that are copied.
>
> Right.  The variables contain object references; these object  
> references are copied (not referenced!) when you pass them into a  
> function.  That's call by value.

snip.

What do you propose the name of the method of passing parameters
should be for the following function 'f' in C?

struct T {
  int a;
  int b;
  int c;
};

void f( T t );

Given a 4-byte system word, how many bytes do you think are copied to
the stack upon calling 'f'?



More information about the Python-list mailing list