Reference Count Confusion

Chris Barker Chris.Barker at noaa.gov
Wed Jun 26 19:08:39 CEST 2002


Jeff Smith wrote:

> import Numeric
> import foo
> 
> a = Numeric.zeros(1000000).astype('f')
> b = Numeric.ones(1000000).astype('f')

A little nit unrelated to your question:

use: a = Numeric.zeros(1000000,'f')

instead. The result is the same, but it creates the Float array
directly, rather than creating an integer array, and then making a float
array from that.

>   return Py_BuildValue("O", c);

You might want to try:

return Py_BuildValue("N", c);

I'm a little fuzzy on al this too, but that works for me in a similar
situation. From Extending and Embedding the Python Interpreter:

"N" (object) [PyObject *] 
      Same as "O", except it doesn't increment the reference count on
the object. Useful when the object is created by a call to an object
constructor in the argument list. 

Good luck,

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer
                                    		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the Python-list mailing list