Interesting Memory Optimization

Alex Rønne Petersen xtzgzorex at gmail.com
Thu Mar 15 19:35:27 PDT 2012


On 16-03-2012 03:31, Xinok wrote:
> 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.

Right. Most compilers do it.

-- 
- Alex


More information about the Digitalmars-d mailing list