Opened 11 years ago

#6073 new Feature Requests

typed subarray from incompatible/raw memory

Reported by: Maxim Yanchenko <Maxim.Yanchenko@…> Owned by: Ronald Garcia
Milestone: To Be Determined Component: multi_array
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

Consider this example:

struct A { double x, y; };

struct B : A { double z; };
struct C { A a; double z; };
struct D { double z; A a; };
struct unknown { ...; A a; ....; };

Let's say I have in memory an n-dimensional array of B, or C, or D, or even unknown structure where I know only total size of the element and offset of A inside it, both in run-time (e.g. a binary file produced by NumPy.mmap).

What I need is a multi_array_view that could behave as an multi_array of A, given the sizeof of "real" element containing A, and offset of A inside it, like this:

void* p = mmap(...);
size_t el_size = size_of_element_in_p;
size_t offset  = offset_of_A_inside_element;

boost::multi_array::multi_array_typed_view<A, NumDims>
  my_view(p, extents, el_size, offset );

Strided view (boost::detail::multi_array::multi_array_view) could do the job in simple cases when size of "real" element is a multiple of sizeof(A), but not in the above case.

Change History (0)

Note: See TracTickets for help on using tickets.