Python and the need for speed
auriocus at gmx.de
Tue Apr 11 02:14:41 EDT 2017
Am 10.04.17 um 02:21 schrieb Gregory Ewing:
> Heck, you can write an exec() function for C if you really
> want. Run the C compiler in another process, dynamically
> load the object file and call it. Doing that would be very
> inefficient, but it wouldn't slow down the rest of your
> C code.
Actually, this thing exists and it is quite useful. tcc can be used as a
library / JIT compiler for C. It does allow both writing to a dynamic
library as well as creating callable functions in memory.
What you can't do with it, however, is access to local variables. i.e.
writing an exec which does this:
exec("i = 5");
printf("%d", i); // prints 5
is impossible in C, and making it possible (via debug symbols, e.g.)
would make the program slower, because C compilers reorder the
instructions and assign variables to registers.
More information about the Python-list