in reply to Reading (the same) data in different ways & memory usage
The probable reason is that you are storing numeric values as PVs--their string representation as read from the file--in addition to IVs--their numeric representation--the generation of which you are deliberately forcing with this code:
if ($self->datatype->[$_] =~ /^(?:TINYINT|MEDIUMINT|SMALLINT|INT|INTEGER|BIGINT|FLOAT|DOUBLE)$/ +) { $hr_returnvalue->{$CurrentColumnName} *= 1; # Multiply by 1 to create a numeric value. }
Having initially loaded the value as a string (PV), when you force it to be converted to a numeric value (IV), the string value will be retained so that if you later decide to use it in a string context, the (inverse) conversion does not have to be repeated.
Eg. After the *= 1;, the PV is still there, but you gained an IV. Essentially you've increased the size of the SV rather than reduce it (as I assume you intended):
C:\test>perl -MDevel::Peek -E"my $x = '12345'; Dump $x; $x *=1; Dump $ +x" SV = PV(0x6cf50) at 0xc74e8 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x67758 "12345"\0 CUR = 5 LEN = 8 SV = PVIV(0xaf018) at 0xc74e8 REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 12345 PV = 0x67758 "12345"\0 CUR = 5 LEN = 8
A fix would be to perform the string->numeric conversion before storing the value:
for( 0 .. $#{$self->columns} ) { $CurrentColumnName = $self->columns->[$_]; if( !(defined $self->flatfield_start->[$_] and defined $self->flatfield_length->[$_] ) ) { # Field is missing interface_start, interface_length or both, skip + it. next; } if ($self->datatype->[$_] =~ /^(?:TINYINT|MEDIUMINT|SMALLINT|INT|INTEGER|BIGINT|FLOAT|DOUB +LE)$/ ) { $hr_returnvalue->{$CurrentColumnName} = 0 + substr( $textinput, $self->flatfield_start->[$_], $self->flatfield_length-> +[$_] ); }else { $hr_returnvalue->{$CurrentColumnName} = substr( $textinput, $self->flatfield_start->[$_], $self->flatfield_length +->[$_] ); $hr_returnvalue->{ $CurrentColumnName } =~ s/^\s*(.*?)\s*$/$1/; # Trim whitespace } # Fill empty fields with that field's default value, if such a value +is defined
That should reduce the size of the final data structure significantly if there are many numeric fields.
|
|---|