Promises in D
Calvin P
cloudlessapp at gmail.com
Thu Apr 8 04:53:47 UTC 2021
On Wednesday, 7 April 2021 at 16:43:59 UTC, Vladimir Panteleev
wrote:
> Reference counting doesn't change the situation. With
> delegates, the resource provider can pass a temporary view into
> an internal buffer owned by the provider. With reference
> counting, you still need to allocate memory dynamically, and
> possibly do an additional copy from the internal buffer to the
> reference-counted one.
I don't think so.
A buffer instance and it' derivative Slice instance can shared
one refCount pointer.
If the Promise no long need own the Buffer just release the
refCount.
If Caller finish with the Buffer, just release the refCount.
If the Buffer need be handle by multi callback cross thread, then
it is passed by const. If callback need modify it then it should
copy the Slice.
A const temporary view (in my case a const Slice) or a non-const
temporary view (a Unique Slice) can work with Atomic refCount
with multi thread safe code.
A Unique Slice will borrow the ownership from Buffer and return
to Buffer when it released.
If the Buffer refCount is zero when Unique Slice released, the
resource is release to object pool for reuse.
I don't see a case your Promise solution can void copy Slice but
refCount need do copy.
More information about the Digitalmars-d
mailing list