Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19202

Re: access address from object and vice versa

References <4F1B7CA8.80702@googlemail.com>
Date 2012-01-22 15:55 +1100
Subject Re: access address from object and vice versa
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4919.1327208121.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Jan 22, 2012 at 2:04 PM, Tamer Higazi <th982a@googlemail.com> wrote:
> Hi people!
> I have asked myself the following thing.
>
> How do I access the address of an object and later get the object from
> that address ?!

The problem with that sort of idea is that it mucks up garbage
collection. CPython, for example, maintains a reference count for
every object; your address is, in a sense, another reference, but one
that the GC doesn't know about - so it might release the object and
reuse the memory.

What you can do, though, is simply have another name bound to the same
object. You can then manipulate the object through that name, and
it'll function just like a pointer would in C. The original name and
the new name will function exactly the same.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: access address from object and vice versa Chris Angelico <rosuav@gmail.com> - 2012-01-22 15:55 +1100

csiph-web