feat: SharedArray:wrapData:withSize
init for iOS (#2410)
* feat: `ArrayBuffer:wrapData:withSize` init for iOS * Format * fix build error * Update ExampleFrameProcessorPlugin.m * docs: Add class docs for SharedArray
This commit is contained in:
@@ -12,17 +12,19 @@
|
||||
|
||||
namespace vision {
|
||||
|
||||
MutableRawBuffer::MutableRawBuffer(uint8_t* data, size_t size, std::function<void()> cleanup)
|
||||
: _data(data), _size(size), _cleanup(std::move(cleanup)) {}
|
||||
MutableRawBuffer::MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc)
|
||||
: _data(data), _size(size), _freeOnDealloc(freeOnDealloc) {}
|
||||
|
||||
MutableRawBuffer::MutableRawBuffer(size_t size) {
|
||||
_size = size;
|
||||
_data = (uint8_t*)malloc(size * sizeof(uint8_t));
|
||||
_cleanup = [=]() { free(_data); };
|
||||
_freeOnDealloc = true;
|
||||
}
|
||||
|
||||
MutableRawBuffer::~MutableRawBuffer() {
|
||||
_cleanup();
|
||||
if (_freeOnDealloc) {
|
||||
free(_data);
|
||||
}
|
||||
}
|
||||
|
||||
size_t MutableRawBuffer::size() const {
|
||||
|
@@ -20,7 +20,7 @@ class MutableRawBuffer : public jsi::MutableBuffer {
|
||||
|
||||
public:
|
||||
explicit MutableRawBuffer(size_t size);
|
||||
explicit MutableRawBuffer(uint8_t* data, size_t size, std::function<void()> cleanup);
|
||||
explicit MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc);
|
||||
~MutableRawBuffer();
|
||||
|
||||
public:
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
private:
|
||||
uint8_t* _data;
|
||||
size_t _size;
|
||||
std::function<void()> _cleanup;
|
||||
bool _freeOnDealloc;
|
||||
};
|
||||
|
||||
} // namespace vision
|
||||
|
Reference in New Issue
Block a user