Interesting Memory Optimization

Xinok xinok at live.com
Thu Mar 15 19:31:46 PDT 2012


On Friday, 16 March 2012 at 02:18:27 UTC, Kevin 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).
>
> Kevin.

I'm pretty sure this is called string pooling.


More information about the Digitalmars-d mailing list