# Memoize to a file

**URL:** <https://rubytalk.org/t/memoize-to-a-file/24562>\
**Category:** ruby-talk\
**Created:** [2 February 2006 15:29 UTC](https://rubytalk.org/t/memoize-to-a-file/24562 "2006-02-02T15:29:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Berger\_Daniel1](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@Berger\_Daniel1](https://rubytalk.org/u/Berger_Daniel1)\
**Post date:** [2 February 2006 15:29 UTC](https://rubytalk.org/t/memoize-to-a-file/24562/1 "2006-02-02T15:29:34Z")

</div>

I guess I'm once bitten, twice shy as a result of the transition from 1.6.8 to 1.8.0 not too long ago. Thanks for the correction.

Dan

> **···**
>
> > -----Original Message-----  
> > From: Mauricio Julio Fernández Pradier  
> > [mailto:ferferse@telefonica.net] On Behalf Of Mauricio Fernandez  
> > Sent: Wednesday, February 01, 2006 4:48 PM  
> > To: ruby-talk ML  
> > Subject: Re: memoize to a file
> > 
> > On Thu, Feb 02, 2006 at 06:49:49AM +0900, Daniel Berger wrote:  
> > \> \> and it instead of silently failing I now see the error  
> > message: "in  
> > \> \> `load': marshal data too short (ArgumentError)"  
> > \> \>  
> > \> \> My questions:  
> > \> \> 1 What is causing this error? (possibly Windows related?)  
> > \>  
> > \> That is odd. I've run it on Windows with no trouble in the past.
> > 
> > (FTR: file not opened in binary mode, [177651])  
> > \> Is it possible you ran this program using 1.8.2, downloaded 1.8.4,  
> > \> then re-ran the same code using the same cache? It would fail with  
> > \> that error if such is the case, since Marshal is not compatible  
> > \> between versions of Ruby - not even minor versions.
> > 
> > The Marshal format hasn't changed for a while:
> > 
> > batsman@tux-chan:~/Anime$ ruby182 -v -e 'p  
> > [Marshal::MAJOR\_VERSION, Marshal::MINOR\_VERSION]' ruby 1.8.2  
> > (2004-12-25) [i686-linux] [4, 8] batsman@tux-chan:~/Anime$  
> > ruby -v -e 'p [Marshal::MAJOR\_VERSION,  
> > Marshal::MINOR\_VERSION]' ruby 1.8.4 (2005-12-24) [i686-linux] [4, 8]
> > 
> > Also note that ruby can read Marshal data in older formats if  
> > the MAJOR\_VERSION hasn't changed (i.e. if only the  
> > MINOR\_VERSION was increased):
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;if (major != MARSHAL\_MAJOR || minor \> MARSHAL\_MINOR) {  
> > &nbsp;&nbsp;rb\_raise(rb\_eTypeError, "incompatible marshal file  
> > format (can't be read)\n\ \tformat version %d.%d required;  
> > %d.%d given",  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MARSHAL\_MAJOR, MARSHAL\_MINOR, major, minor);  
> > &nbsp;&nbsp;&nbsp;&nbsp;}  
> > &nbsp;&nbsp;&nbsp;&nbsp;if (RTEST(ruby\_verbose) && minor != MARSHAL\_MINOR) {  
> > &nbsp;&nbsp;rb\_warn("incompatible marshal file format (can be  
> > read)\n\ \tformat version %d.%d required; %d.%d given",  
> > &nbsp;&nbsp;&nbsp;&nbsp;MARSHAL\_MAJOR, MARSHAL\_MINOR, major, minor);  
> > &nbsp;&nbsp;&nbsp;&nbsp;}
> > 
> > (after some searching...)
> > 
> > Back in Apr. 2001, matz said that "Marshal should not change  
> > too much (unless in upper compatible way)" [14063]. The last  
> > minor change happened after 1.6.8 (6 -\> 8), and MARSHAL\_MAJOR  
> > was already 4 in v1\_0\_1, 7 years, 2 months ago (at which  
> > point I got tired of CVSweb).
> > 
> > Marshal's format is more stable than we think.
