From df3103622b7de05f4e35b22a2c94b4a46eab4efc Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Wed, 14 Nov 2018 13:16:56 +0000 Subject: COMPMID-1088: Use IMemoryRegion in interfaces where possible -Simplifies import memory interface -Changes the used of void** handles with appropriate interfaces. Change-Id: I5918c855c11f46352058864623336b352162a4b7 --- arm_compute/runtime/MemoryRegion.h | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'arm_compute/runtime/MemoryRegion.h') diff --git a/arm_compute/runtime/MemoryRegion.h b/arm_compute/runtime/MemoryRegion.h index 481b20d375..335486ed9d 100644 --- a/arm_compute/runtime/MemoryRegion.h +++ b/arm_compute/runtime/MemoryRegion.h @@ -37,13 +37,13 @@ namespace arm_compute class MemoryRegion final : public IMemoryRegion { public: - /** Default constructor + /** Constructor * * @param[in] size Region size * @param[in] alignment Alignment in bytes of the base pointer. Defaults to 0 */ MemoryRegion(size_t size, size_t alignment = 0) - : IMemoryRegion(size), _mem(nullptr), _alignment(alignment), _offset(0) + : IMemoryRegion(size), _mem(nullptr), _ptr(nullptr) { if(size != 0) { @@ -53,16 +53,25 @@ public: { delete[] ptr; }); + _ptr = _mem.get(); // Calculate alignment offset if(alignment != 0) { void *aligned_ptr = _mem.get(); support::cpp11::align(alignment, size, aligned_ptr, space); - _offset = reinterpret_cast(aligned_ptr) - reinterpret_cast(_mem.get()); + _ptr = aligned_ptr; } } } + MemoryRegion(void *ptr, size_t size) + : IMemoryRegion(size), _mem(nullptr), _ptr(nullptr) + { + if(size != 0) + { + _ptr = ptr; + } + } /** Prevent instances of this class from being copied (As this class contains pointers) */ MemoryRegion(const MemoryRegion &) = delete; /** Default move constructor */ @@ -75,22 +84,27 @@ public: // Inherited methods overridden : void *buffer() final { - return reinterpret_cast(_mem.get() + _offset); + return _ptr; } void *buffer() const final { - // FIXME (COMPMID-1088) : Remove handle() and _offset when done - return reinterpret_cast(_mem.get() + _offset); + return _ptr; } - void **handle() final + std::unique_ptr extract_subregion(size_t offset, size_t size) final { - return reinterpret_cast(&_mem); + if(_ptr != nullptr && (offset < _size) && (_size - offset >= size)) + { + return support::cpp14::make_unique(static_cast(_ptr) + offset, size); + } + else + { + return nullptr; + } } protected: std::shared_ptr _mem; - size_t _alignment; - size_t _offset; + void *_ptr; }; } // namespace arm_compute #endif /* __ARM_COMPUTE_RUNTIME_MEMORY_REGION_H__ */ -- cgit v1.2.1