in reply to Reducing Memory Usage

Okay. This is just a skeleton, but this creates 50,000 Bus objects, and gives each of them 33 x 80-byte timetables. All are individually getable and setable. All fully OO (externally).

Total data: 50,000 * 33 * 80 = 125 MB.

Total process memory consumed: 140 MB.

Adding methods to manipulate the data is just a case of each method calling the get() routine and then splitting the data into it's constituent bits to manipulate. Trading a little time for memory.

#! perl -slw use strict; package Buses; sub new { my( $class, $timeTablesObj ) = @_; return bless \$timeTablesObj, $class; } sub getTimeTable { my( $self, $id ) = @_; return $$self->get( $id ); } sub setTimeTable { my( $self, $id, $new ) = @_; return $$self->set( $id, $new ); } package Timetables; sub new{ my( $class, $timetable ) = @_; return bless \$timetable, $class; } sub get{ my( $self, $id ) = @_; ## Numeric ID, zero based return substr $$self, $id*80, 80; } sub set{ my( $self, $id, $new ) = @_; substr $$self, $id*80, 80, pack 'a80', $new; } package main; my @buses = map { my $timeTable = Timetables->new( join '', map{ pack 'A80', $_ } 0 .. 33 ); Buses->new( $timeTable ); } 1 .. 50_000; print $buses[ 49_000 ]->getTimeTable( 29 ); <STDIN>;

Or if you need text-key access to your buses using a hash pushes it to 150 MB.

#! perl -slw use strict; package Buses; sub new { my( $class, $timeTablesObj ) = @_; return bless \$timeTablesObj, $class; } sub getTimeTable { my( $self, $id ) = @_; return $$self->get( $id ); } sub setTimeTable { my( $self, $id, $new ) = @_; return $$self->set( $id, $new ); } package Timetables; sub new{ my( $class, $timetable ) = @_; return bless \$timetable, $class; } sub get{ my( $self, $id ) = @_; ## Numeric ID, zero based return substr $$self, $id*80, 80; } sub set{ my( $self, $id, $new ) = @_; substr $$self, $id*80, 80, pack 'a80', $new; } package main; my %buses = map { my $timeTable = Timetables->new( join '', map{ pack 'A80', $_ } 0 .. 33 ); ( "BusID:$_", Buses->new( $timeTable ) ); } 1 .. 50_000; print $buses{ "BusID:49001" }->getTimeTable( 29 ); <STDIN>;

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon