python - Ctypes - basic explanation -


i'm trying speed integration (scipy.integrate.quad) using ctypes. have never used c , don't understand ctypes documentation. give basic explanation of ctypes doing using few computing terms possible. please explain i'm 5!

thanks

a computer runs program following simple steps, known machine code or native code. @ level, number of handful of widths, , there millions of memory slots store them in. when writing program, higher level of abstraction desired, allowing name variables , subroutines, keep track of memory holds value, , on. native code not reveal information, stored program files (whether libraries or executables) have clues, such subroutine names. c source code supplies information in declarations, , libraries scipy have wrappers preserve information layer up, in case python. python objects hold information on types, unlike c variables. ctypes permits names , describe missing type information, native variables , subroutines can accessed python. in scipy.integrate.quad example, ctypes used create python function object native subroutine named func.

>>> import ctypes >>> lib = ctypes.cdll('/home/.../testlib.*') #use absolute path >>> lib.func.restype = ctypes.c_double >>> lib.func.argtypes = (ctypes.c_int,ctypes.c_double) 

in c terms, function declared extern double func(int, double);. in general, native routines faster python ones, because python has figure out each operation objects handles, while information statically determined in c. middle ground can reached in time compilers, of pypy example.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -