Memory management

  • Thread starter Marcelo A. Camelo
  • Start date
M

Marcelo A. Camelo

WARNING: long post ahead!

I've been researching the feasibility of using Python for the
development of commercial games and I will be giving a presentation
about this subject at the Australian Game Developers Conference by the
end of the month, in Melbourne.

Python memory management happens to be one of the greatest reasons
that game developers resist the ideia of taking Python seriously in
commercial titles, specially for console development. But it seems
that most people complainning used pre 2.0 versions and have never
heard about the Specialized Small Object Allocator. From what I've
learned (mostly from reading PyAlloc source code), python new memory
allocator solves most of the problems faced by game developers.

Bellow is a summary of what I will take to the conference in respect
to Python memory management. Am I on the right track or am I missing
some fundamental truth? I would appreciate any feedback that can
improve the usefulness of the information I will be taking to game
developers.

[summary]
One of the most common complaint I've heard from game developers had
to do with Python's bad memory habbits and the lack of control over
how Python manages memory at the low level. The problem is that, in
Python, every object is allocated dynamically from the heap and
allocations occur very frequently. Even simple ints are objects
allocated from the heap. Relying on standard C malloc and with the
large number of allocations and deallocations taking place even on
simple algorithms, severe memory fragmentation will inevitably occour,
along with the associated performance overhead of fitting memory
requests.

Worse yet is that, differently from CPU time which you can inpect with
a profiler, memory usage is impossible to assess without writting your
own memory manager.

Since Python 2.3, most of these problems have been solved. Python now
comes equipped with the Specialized Small Object Allocator, known as
PyAlloc. PyAlloc has been part of python since version 2.1, but until
version 2.3, it was an optional feature that had to be explicitly
enabled when building python from the sources. Since its first
appearance in 2001, PyAlloc has been tested and improved. In 2003 it
was considered mature enough to become Python's default memory
manager.

PyAlloc implements a modified segmented allocator based on free lists.
This allocation is optimized for frequent allocation and deallocation
of small memory blocks, the most common case in Python programs, being
able to serve memory requests with negligible overhead. Requests for
big blocks are forwarded to the underlying system memory allocator.

By segmenting memory request on the basis of their sizes, PyAlloc
solves the problem of external fragmentation, with the cost of some
negligible internal fragmentation. Also, when built with the
appropriated compilation options, PyAlloc is able to provide
comprehensive memory usage statistics.
[/summary]

Any comments?

Best regards,

Marcelo A. Camelo
 
K

KefX

I've been researching the feasibility of using Python for the
development of commercial games

[snip]

I've believed in the viability of Python for commercial games as soon as I
really got acquainted with the language. As a budding game designer and
programmer myself, I'm happy to find yet another reason to support the notion.
:)

High-level languages are undoubtedly (to me at least) much, MUCH better suited
to designing games than low-level languages (I didn't know just how low-level C
really was until I learned Python). It's just that low-level languages have
dominated because total control of the machine at all times had paramount
importance...an importance that's rapidly decreasing.

- Kef
 
A

Aahz

Since Python 2.3, most of these problems have been solved. Python now
comes equipped with the Specialized Small Object Allocator, known as
PyAlloc. PyAlloc has been part of python since version 2.1, but until
version 2.3, it was an optional feature that had to be explicitly
enabled when building python from the sources. Since its first
appearance in 2001, PyAlloc has been tested and improved. In 2003 it
was considered mature enough to become Python's default memory
manager.

Two points:

* s/PyAlloc/PyMalloc/

* There have been several commercial games, including at least one
real-time first-person game (Blade of Darkness), based on versions of
Python prior to 2.3, so even before PyMalloc, Python's memory management
was far from an insurmountable obstacle. I don't know whether any of
those games enabled PyMalloc, but I doubt it.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top