Tuple size and memory allocation for embedded Python

Jinming Xu cybermanxu at hotmail.com
Fri Jan 21 17:03:51 EST 2005


Hi Folks,

Python seems unstable, when allocating big memory.  For example, the 
following C++ code creates a tuple of tuples:

  PyObject* arCoord = PyTuple_New(n);
  double d = 1.5;
  for(int i=0; i<n; i++)
    {
      PyObject* coord = PyTuple_New(2);
      PyTuple_SetItem(coord,0, PyFloat_FromDouble(d));//x
      PyTuple_SetItem(coord,1, PyFloat_FromDouble(d));//y
      PyTuple_SetItem(arCoord,i, coord);
    }

When the n is small, say 100, the code works fine.  when n is big, say 
10,000, Python has trouble allocating memory, saying:

"Exception exceptions.IndexError: 'tuple index out of range' in 'garbage 
collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted"

Could anyone please give me some insight or a fix for this?

Thanks in advance for your answer.

Jinming Xu

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963




More information about the Python-list mailing list