Interesting Memory Optimization

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 19 16:20:05 PDT 2012


On Tue, Mar 20, 2012 at 12:05:55AM +0100, Timon Gehr wrote:
> On 03/19/2012 01:33 PM, Derek wrote:
> >On Fri, 16 Mar 2012 13:16:18 +1100, Kevin <kevincox.ca at gmail.com> wrote:
> >
> >>This is in no way D specific but say you have two constant strings.
> >>
> >>const char[] a = "1234567890";
> >>// and
> >>const char[] b = "67890";
> >>
> >>You could lay out the memory inside of one another. IE: if a.ptr = 1
> >>then b.ptr = 6. I'm not sure if this has been done and I don't think
> >>it would apply very often but it would be kinda cool.
> >>
> >>I thought of this because I wanted to pre-generate hex-representations
> >>of some numbers I realized I could use half the memory if I nested
> >>them. (At least I think it would be half).
> >
> >Is the effort to do this really an issue with today's vast amounts of
> >RAM (virtual and real) available? How much memory are you expecting to
> >'save'?
> >
> 
> Using less memory means having less cache misses and therefore
> improved performance. Saving half the memory can make quite a
> difference.

While the *total* amount of memory used may not matter so much, cache
locality matters a LOT. The difference between an inner loop that can
run with all accessed memory within the CPU cache and an inner loop that
triggers >=1 cache misses per iteration (due to accessing memory that
happens to exceed cache size just by a little) is *huge*.

Disregarding memory usage just because of the abundance of memory is a
fallacy.


T

-- 
What do you mean the Internet isn't filled with subliminal messages? What about all those buttons marked "submit"??


More information about the Digitalmars-d mailing list