aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/runtime/MemoryRegion.h
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-11-14 13:16:56 +0000
committerIsabella Gottardi <isabella.gottardi@arm.com>2018-11-21 09:52:04 +0000
commitdf3103622b7de05f4e35b22a2c94b4a46eab4efc (patch)
tree17e10253e7a069c69d10bea0882b699b99d74b86 /arm_compute/runtime/MemoryRegion.h
parentc47ef20d69e8ea0f519fdc679435cd7037fc18fe (diff)
downloadComputeLibrary-df3103622b7de05f4e35b22a2c94b4a46eab4efc.tar.gz
COMPMID-1088: Use IMemoryRegion in interfaces where possible
-Simplifies import memory interface -Changes the used of void** handles with appropriate interfaces. Change-Id: I5918c855c11f46352058864623336b352162a4b7
Diffstat (limited to 'arm_compute/runtime/MemoryRegion.h')
-rw-r--r--arm_compute/runtime/MemoryRegion.h34
1 files changed, 24 insertions, 10 deletions
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<uintptr_t>(aligned_ptr) - reinterpret_cast<uintptr_t>(_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<void *>(_mem.get() + _offset);
+ return _ptr;
}
void *buffer() const final
{
- // FIXME (COMPMID-1088) : Remove handle() and _offset when done
- return reinterpret_cast<void *>(_mem.get() + _offset);
+ return _ptr;
}
- void **handle() final
+ std::unique_ptr<IMemoryRegion> extract_subregion(size_t offset, size_t size) final
{
- return reinterpret_cast<void **>(&_mem);
+ if(_ptr != nullptr && (offset < _size) && (_size - offset >= size))
+ {
+ return support::cpp14::make_unique<MemoryRegion>(static_cast<uint8_t *>(_ptr) + offset, size);
+ }
+ else
+ {
+ return nullptr;
+ }
}
protected:
std::shared_ptr<uint8_t> _mem;
- size_t _alignment;
- size_t _offset;
+ void *_ptr;
};
} // namespace arm_compute
#endif /* __ARM_COMPUTE_RUNTIME_MEMORY_REGION_H__ */