1

{Moose,Mouse,Moo} object normally translates to a blessed hashref. Can it use blessed arrayref instead, for compact storage? Think an object like bless({long_attribute_name=>1, another_long_attribute_name=>2, and_a_bunch_of_these=>3}, 'SomeClass') vs bless([1, 2, 3, ...], 'SomeClass'). Since the code using the class will be accessing attributes via accessors, and accessors are all generated in Mo[ou]*, this should in theory be possible, am I correct?

Or, any other strategy for compact storage of objects? I prefer to use Mo[ou]* if possible. I'm planning to load a large number of objects into memory. (Also, this might be another question, some of those objects are DateTime objects, where the above strategy is ineffective because the DateTime code accesses attributes the directly.)

Steven Haryanto
  • 741
  • 5
  • 13
  • I don't think this is possible using {Moose,Mouse,Moo}. If you really want to save memory you could probably code a system using an arrayref as object base, but then without using the benefits of Mo*. – dgw Jul 18 '12 at 12:23
  • See the accepted answer for [this question](http://stackoverflow.com/questions/3828678/should-i-choose-a-hash-an-object-or-an-array-to-represent-a-data-instance-in-pe). The point is that switching to array-based objects may not save you as much memory as you might expect. However, a possible alternative that creates array-based objects is [Class::Accessor::Faster](https://metacpan.org/module/Class::Accessor::Faster). – stevenl Jul 19 '12 at 02:59
  • Note that the main benefit of switching to array-based objects is speed, especially for lots of objects. On that note, I found it better to use [Time::Piece](https://metacpan.org/module/Time::Piece) in place of [DateTime](https://metacpan.org/module/DateTime) if you don't need such an extensive date/time module. – stevenl Jul 19 '12 at 03:06

0 Answers0