C interface provides a pointer and a length... wrap without copying?
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 11 18:50:48 PST 2017
cy wrote:
> On Saturday, 11 March 2017 at 23:43:54 UTC, Nicholas Wilson wrote:
>> A string *is* a pointer length pair, an immutable(char)[].
>
> Yes, but surely there's some silly requirement, like that the pointer
> must only ever point to garbage collected memory, or something?
why should it? a slice can point anywhere, and GC is smart enough to know
what memory it owns and what it isn't. if you'll try to append something to
non-GC-owned slice, GC will make a copy first. so the only requirement is:
"don't use `~=` on it if you don't want to have a memory leak".
More information about the Digitalmars-d-learn
mailing list