hidl_vec: optionally pass buffer ownership in setToExternal
Change-Id: I035231712544ae34b7ee5ff92cc924e18f5f8f96
Signed-off-by: Alexey Polyudov <apolyudov@google.com>
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index b1bb6ed..3b539bc 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -93,16 +93,16 @@
mBuffer = NULL;
}
- // Reference an existing array _WITHOUT_ taking ownership. It is the
+ // Reference an existing array, optionally taking ownership. It is the
// caller's responsibility to ensure that the underlying memory stays
// valid for the lifetime of this hidl_vec.
- void setToExternal(T *data, size_t size) {
+ void setToExternal(T *data, size_t size, bool shouldOwn = false) {
if (mOwnsBuffer) {
delete [] mBuffer;
}
mBuffer = data;
mSize = size;
- mOwnsBuffer = false;
+ mOwnsBuffer = shouldOwn;
}
T *data() {