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:
Marc Rousavy
2024-01-18 10:41:26 +01:00
committed by GitHub
parent e21a1c2110
commit 992934e00e
8 changed files with 56 additions and 21 deletions

View File

@@ -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 {

View File

@@ -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