C interface provides a pointer and a length... wrap without copying?
cy via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 11 14:39:02 PST 2017
So a lovely C library does its own opaque allocation, and
provides access to the malloc'd memory, and that memory's length.
Instead of copying the results into garbage collected memory
(which would probably be smart) I was thinking about creating a
structure like:
struct WrappedString {
byte* ptr;
size_t length;
}
And then implementing opIndex for it, and opEquals for all the
different string types, and conversions to those types, and then
it occurred to me that this sounds like a lot of work. Has
anybody done this already? Made a pointer/length pair, that acts
like a string?
More information about the Digitalmars-d-learn
mailing list