How to map size_t using ctypes?

Philip Semanchuk philip at
Mon Jul 6 12:29:21 EDT 2009

On Jul 6, 2009, at 12:10 PM, Diez B. Roggisch wrote:

> Philip Semanchuk wrote:
>> Hi all,
>> I can't figure out how to map a C variable of size_t via Python's
>> ctypes module. Let's say I have a C function like this:
>> void populate_big_array(double *the_array, size_t element_count)  
>> {...}
>> How would I pass parameter 2? A long (or ulong) will (probably) work
>> (on most platforms), but I like my code to be more robust than that.
>> Furthermore, this is scientific code and it's entirely possible that
>> someone will want to pass a huge array with more elements than can be
>> described by a 32-bit long.
> from ctypes import c_size_t
> doesn't work for you? On my system, it's aliased to c_ulong, but I  
> guess
> that's depending on the platfrom of course.

D'oh! [slaps forehead]

That will teach me to RTFM. In my 2.5 doc, it's not listed in the  
"Fundamental data types" section in the tutorial, but it is mentioned  
in "Fundamental data types" in the ctypes reference. You'd be  
surprised at the amount of Googling I did without learning this on my  


More information about the Python-list mailing list