Emanuele Ricci wrote:
> I just discovered that ruby allocates memory in 8Mb chunks.
> Forgive my ignorance.
> Is there a way to change this behaviour? Since my app runs in an
> environment with very strict memory constraints, a memory spike of 8Mb
> can be lethal...
> I would change it to a lower figure.
> It doesn't matter if I have to patch my ruby source files in order to
> achieve this goal.
> Any clues?
> 
> Thank you in advance,
> Emanuele Ricci.

That may not be Ruby's fault entirely. In many cases, the size of memory 
chunks delivered by "malloc" and its friends is determined by the 
compiler or operating system. I've worked on systems where you got the 
next higher power of two, for example. If you asked for 5,000 you got 
8192, if you asked for 65 you got 128, etc. And many modern systems 
won't give you less than a physical page.

A physical page on most x86 operating systems is 4096 bytes, so 8 MB is 
2048 pages. There is also an option to run larger pages in Linux. What 
OS and architecture are you on?

P.S.: I'm cross-posting this to ruby-core -- that's where patches are 
discussed.