in reply to Re^2: when to c, when to perl
in thread when to c, when to perl
There absolutely are ways to reduce memory usage in Perl programs. And in most cases they are sufficient.
However in cases where the volume of data to be handled is large (eg processing dna sequences) or the system is resource constrained (eg a small ARM linux based appliance) it makes sense to consider a C implementation.
Let's consider an example where I have confronted this issue. I've been working on software for an ARM system that has only 32 MB of RAM and no virtual memory. One can write a simple socket based server in C that has much smaller memory needs than the equivalent perl server. The downside, is that it is harder make the C server do anything useful. I wrote my server application in Perl first, and it fits nicely on the system. However, I know that I can get rid of a fair amount of overhead if I rewrite the server in C. I won't do that unless it becomes absolutely necessary. Perl is much easier to debug, extend and maintain.
In the case above, adding the BerkelyDB to the mix would just make things worse. In data intensive applications, a dbfile is often the answer. Other times simple things like using the ternary for loop instead of for (0..$#bigArray) can make a big difference.
C has it's own problems. Did I forget to free that chunk of memory? Oops--memory leak. Just because it is possible to write more efficient code in C does not mean that C code will always be more efficient. So, you've got to be selective with what you try to do in C.
My basic position is that premature optimization is a bad thing. Writing code in C instead of Perl is an acceptable, if costly (in terms of labor) speed and memory optimization. So, before applying that optimization, make damn sure there aren't any less expensive tricks you can try that will yeild acceptable results AND be sure that your C code will, in fact be smaller/faster than the Perl it replaces.
TGI says moo
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: when to c, when to perl
by MadraghRua (Vicar) on Jul 25, 2008 at 20:51 UTC | |
by TGI (Parson) on Jul 26, 2008 at 01:19 UTC | |
by tilly (Archbishop) on Jul 25, 2008 at 21:58 UTC | |
Re^4: when to c, when to perl
by mr_mischief (Monsignor) on Aug 01, 2008 at 17:50 UTC |