Just want to know WNOHANG...
package MyApp;
# I just want to know WNOHANG from sys_wait_h ... [-;
our $WNOHANG_VALUE ||= `$^X -MPOSIX=:sys_wait_h -e "print WNOHANG;"`;
sub WNOHANG () { $WNOHANG_VALUE }
!!'^^';
sigh maybe useful for a long-time running program if you are sensitive to memory usage..
Why do you need to start up a whole new process just to get a constant?
Friedo, he wants to avoid loading POSIX.pm in the current process, since it's a rather large module, and usually ends up consuming several megabytes of memory.
I can see how that could be a concern if you have a long-running process, especially something that does pre-forking, or you're in a memory-constrained environment.
Obviously, in most cases this won't be an issue, and I hope that no one adopts this technique without making 100% sure it's necessary.
Maybe a better way would be to put this logic in a build/install script, which would define the constants in a config file that gets installed with the module. That way at least you don't have to execute the same hackery every runtime.
POSIX.pm is actually not so large, since it uses AutoLoader to dynamically choose only necessary bits of code.
$ wc -l /usr/lib/perl/5.8/auto/POSIX/*.al | tail -1
2096 total
$ wc -l /usr/lib/perl/5.8/POSIX.pm
61 /usr/lib/perl/5.8/POSIX.pm
I realized that an installer can do this.
but sometimes I put this kind of script in a archive or USB like using a PortableApps
and in that case, this ensure the correct value of constant.
thank you for reply. (-:
use POSIX qw(:sys_wait_h);
will increase about 1MiB of memory in my system.
This may be or may not be considerable.
but I guess using several modules would result in 3~5MiB increase without any useful things.
It's an method to avoid loading too much,
and I'm looking for other methods as well, in the other cases, such as loading just necessary plugins by check and then load actually into the current process.
It's not a best way though. because it has overhead to fork another process and read hard disk more often. It's totally an option.