On Friday, 16 March 2012 at 11:41:59 UTC, Alex Rønne Petersen
wrote:
On 16-03-2012 12:32, Peter Alexander wrote:
On Friday, 16 March 2012 at 02:31:47 UTC, 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.
My understanding is that string pooling just shares whole
strings rather
than combining suffixes.
e.g.
const char[] a = "fubar";
const char[] b = "fubar"; // shared
const char[] c = "bar"; // not shared at all
Combining suffixes is obviously possible, but I'm not sure
that string
pooling implies suffix pooling.
I don't see any reason why c couldn't point to element number 3
of b, and have its length set to 3...
Neither do I, but it's more work for the compiler, and even if
the compiler does string pooling, it may not look for common
suffixes.