7

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!

Massoud
  • 175
  • 1
  • 7
  • 2
    Somebody is still using valarray? – Puppy Jun 21 '12 at 17:07
  • 2
    @DeadMG What is the alternative? Want to use vectors holding values only, and their usage should be, if possible, as convenient as in Matlab. And valarrays seem as they could fulfill my need (for numerical calculation). – Massoud Jun 22 '12 at 06:50
  • @DeadMG I use it regularly. Its interface makes it easy to write generic algorithms that work with both scalars and vectors. And since it is part of the standard you don't have to rely on yet another library. – Bowie Owens Jul 04 '12 at 01:44
  • 1
    @DeadMG what do you use in place of valarray? – a06e Mar 06 '14 at 18:49

1 Answers1

13

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.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111