Skip Menu |

This queue is for tickets about the File-Type CPAN distribution.

Report information
The Basics
Id: 15777
Status: open
Priority: 0/
Queue: File-Type

People
Owner: Nobody in particular
Requestors: adamk [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.22
Fixed in: (no value)



Subject: File::Type uselessly copies contents
File::Type doubles the code of having a file in memory. For example use File::Type; my $foo = 'x' x 10000000; # A 10 meg string my $mime = File::Type->checktype_contents($foo); That will allocate _another_ 10 meg of data. Rather than just take what it needs off the head of the file, File::Type seems to copy the entire thing (although only once). Might want to add a little more code to take care you are working with the alias directly, rather than copying, or copy only the small part of the file you need.
On Mon Nov 14 10:23:46 2005, ADAMK wrote: Show quoted text
> File::Type doubles the code of having a file in memory. > > For example > > use File::Type; > my $foo = 'x' x 10000000; # A 10 meg string > my $mime = File::Type->checktype_contents($foo); > > That will allocate _another_ 10 meg of data. Rather than just take > what it needs off the head of the file, File::Type seems to copy the > entire thing (although only once). > > Might want to add a little more code to take care you are working with > the alias directly, rather than copying, or copy only the small part > of the file you need. >
Are you sure that your analysis is right? Note that the line my $foo = 'x' x 10000000; # A 10 meg string causes perl to always hold the 10 meg string twice. This is an optimization for any constant string build with x. Probably perl should have an upper limit where this optimization occurs. Regards, Slaven