My code gets some data from an OpenCV cv::Mat object, and passes it to some 
Swift code that takes it via an UnsafePointer<UInt8> parameter. This works fine 
until I want to make the call asynchronous (using a DispatchQueue), I think 
because the underlying cv::Mat gets deallocated by the caller before the async 
method completes.

So I want to make a copy of it to hold onto during the async operation. I tried 
this:

    let copy = UnsafeMutablePointer<UInt8>.allocate(capacity: 
inSourceBufferLength)
    copy.initialize(from: inSourceBuffer, count: inSourceBufferLength)
                
    self.queue.async
    {
        self.foo(data: copy, length: inSourceBufferLength)
    }

But that doesn't seem to be working. Is UnsafeMutablePointer<> not memory 
managed?

I'd also like to keep immutable semantics throughout, but I can forego that if 
it makes things really messy.

-- 
Rick Mann
rm...@latencyzero.com


_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to