[PYTHON MATRIX-SIG] A related idea

Hinsen Konrad hinsenk@ere.umontreal.ca
Thu, 9 Nov 1995 14:47:10 -0500

   The point isn't that I want to save memory but that I want to MODIFY the
   array the compiled code is using, such as an array in a Fortran common block.

We should make a difference between Fortran and C interfacing (C
standing for all languages that can handle dynamic memory management
in a reasonable way). Fortran arrays are always static, so there
is no memory leak problem. Increasing the reference count to make
sure Python never tries to free the memory should be sufficient.

As for C, the best way would be to leave allocation completely to
Python. The matrix module would provide functions to allocate and free
matrices that can be called from the C code just like malloc() and
free(). These functions would take care of the reference from the C

Of course the C code is also free to handle its own matrices and
manage them completely (e.g. workspace in library functions). These
would never be accessed from Python; in fact, Python wouldn't even
know about their existence.

Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)

MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org