min and max id numbers

R

r.e.s.

Just curious ...

On a given machine, is it possible to create objects LO and HI,
such that for all objects x, id(LO) <= id(x) <= id(HI) ?

--r.e.s.
 
P

Paul Rubin

r.e.s. said:
On a given machine, is it possible to create objects LO and HI,
such that for all objects x, id(LO) <= id(x) <= id(HI) ?

It may be possible under narrow circumstances but you really can't
ever rely on it. You're better off writing a C extension that tells
you the endpoints of heap memory.
 
T

Terry Reedy

r.e.s. said:
Just curious ...

On a given machine, is it possible to create objects LO and HI,
such that for all objects x, id(LO) <= id(x) <= id(HI) ?

You have no control over the id of PyObjects. id's are mostly for internal
use of the interpreter.

tjr
 
R

r.e.s.

Terry Reedy said:
...

You have no control over the id of PyObjects.
id's are mostly for internal use of the interpreter.

Still, if it were a game played on one machine, surely
some of the experts around here could come pretty close
to finding a LO and a HI object. No?
 
P

Paul Rubin

r.e.s. said:
Still, if it were a game played on one machine, surely
some of the experts around here could come pretty close
to finding a LO and a HI object. No?

The id of an object in CPython is just its memory address. Obviously
you could not guarantee the HI object staying higher than all the
other objects since the interpreter can always allocate more memory.
To do what you're asking you'd have to modify the interpreter to have
a new kind of sentinel object and have ident return special values for
those objects. I guess you could do that if you really wanted, but it
would be a crazy crock.
 
D

Dennis Lee Bieber

r.e.s. fed this fish to the penguins on Friday 05 December 2003 21:41
pm:
Still, if it were a game played on one machine, surely
some of the experts around here could come pretty close
to finding a LO and a HI object. No?

While not a certainty, and subject to change in the future, hasn't it
been reported that object IDs are essentially the memory address of the
object? If so, then object LO would have to be equivalent to the lowest
addressable memory, and object HI would have to be the highest
(virtual?) addressable memory.

You could probably define /values/ LO and HI... but I don't think,
without modifications to the Python compiler/interpreter to /not/
expect addresses for those two "constants" -- ie, return the value as
the ID -- you could get real objects for those bounds.

--
 
R

r.e.s.

The id of an object in CPython is just its memory address. Obviously
you could not guarantee the HI object staying higher than all the
other objects since the interpreter can always allocate more memory.
To do what you're asking you'd have to modify the interpreter to have
a new kind of sentinel object and have ident return special values for
those objects. I guess you could do that if you really wanted, but it
would be a crazy crock.

Well, I only meant it as a "crazy crock" kind of game, but without
modifying the interpreter. Suppose Jane is allowed N keystrokes
at Python's interactive window, then likewise for John, and none
of their own code can be imported. Say anyone making the machine
hang, or not come back to the prompt within 5 minutes, loses. The
machine only has so much memory, so is it really obvious that John
can always create an object HI-er than any of Jane's? (Sorry if
in my ignorance I'm imagining an altogether ridiculous scenario ;o)
 
P

Paul Rubin

r.e.s. said:
Well, I only meant it as a "crazy crock" kind of game, but without
modifying the interpreter. Suppose Jane is allowed N keystrokes
at Python's interactive window, then likewise for John, and none
of their own code can be imported. Say anyone making the machine
hang, or not come back to the prompt within 5 minutes, loses. The
machine only has so much memory, so is it really obvious that John
can always create an object HI-er than any of Jane's? (Sorry if
in my ignorance I'm imagining an altogether ridiculous scenario ;o)

What I don't think you can do is make an object "Hi" which necessarily
has a higher address than all other objects in the same Python
instance, including those created later than "Hi", without modifying
the interpreter. I thought that's what you were asking.
 
D

Dennis Lee Bieber

r.e.s. fed this fish to the penguins on Saturday 06 December 2003 00:42
am:
Well, I only meant it as a "crazy crock" kind of game, but without
modifying the interpreter. Suppose Jane is allowed N keystrokes
at Python's interactive window, then likewise for John, and none
of their own code can be imported. Say anyone making the machine
hang, or not come back to the prompt within 5 minutes, loses. The
machine only has so much memory, so is it really obvious that John
can always create an object HI-er than any of Jane's? (Sorry if
in my ignorance I'm imagining an altogether ridiculous scenario ;o)
On a virtual memory system, theoretically /each/ process sees what
looks like the entire available memory range. Both "John" and "Jane"
can create objects with the /same/ ID (same virtual memory address) --
but those objects will exist in different physical memory blocks and,
depending on machine loading, at times one or both may even exist in
the swap file on disk and not even be in physical memory.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top