Does valarray have contiguous memory alignment?

2020-02-13 13:50发布

问题:

Does valarray have contiguous memory alignment?

I want to pass a valarray to a function (from IPPS), which only takes pointers, by passing &myValarray[0]. But therefore I should be sure, that valarray's memory alignment is contiguous.

Thanks!

回答1:

Assuming you're asking whether the memory managed by a valarray is guaranteed to be contiguous, then the answer is yes, at least if the object isn't const (C++03, §26.3.2.3/3 or C++11, §26.6.2.4/2):

The expression &a[i+j] == &a[i] + j evaluates as true for all size_t i and size_t j such that i+j is less than the length of the non-constant array a.