interpreter vs. compiled

castironpi castironpi at
Thu Jul 24 06:35:38 CEST 2008

On Jul 23, 12:08 pm, "Martin v. Löwis" <mar... at> wrote:
> >> Oh.  How is the stack represented?
> > As usual, as successive locations in memory.
> > I have the impression that CPython uses the same stack C does.
> Actually, it doesn't (at least not for the evaluation stack).
> In CPython, when a Python function starts, the maximum depth of the
> evaluation stack is known, but it depends on the specific function
> (of course). So Python needs to allocate an array for the evaluation
> stack with known size, but can't do so on the C stack (at least not
> portably), since you can't allocate dynamically-sized array as
> a local variable in C.
> So instead, pymalloc is used to allocate the evaluation stack, and
> it is part of the frame object (so the entire frame object is allocated
> in one chunk, and then split up into local variables and evaluation
> stack.
> > While conceptually, CPython may put objects on the stack, I am pretty
> > sure it actually stacks references (C pointers) to objects in heap memory.
> Correct.
> >> Does it keep track of which stack
> >> positions (TOS, TOS1, etc.) are in what registers?
> > I am sure they are not in registers, just normal memory.
> Correct. As discussed above, they are located on the heap (making
> Python's frame stack a spaghetti stack).
> Regards,
> Martin


I am curious and pursuing it as an independent project.  I'd like to
write a specialized function to allocate memory from an memory-mapped
file instead of the heap.  On Windows, to use CreateFileMapping and
MapViewOfFile.  The companion function, premalloc, would re-open an
existing Python object from a handle.  (It would need a name or index -
> offset look-up.) is down, so I can't tell if Python already implements
its own memory management, and if so how that would extrapolate to a
byte-array allocated specifically.

More information about the Python-list mailing list