Adam Hunyadi
Adam Hunyadi

Reputation: 1952

Is it safe to access std::array data by address?

I would like to use bitwise data conversion on std::array objects and for this I need to know if it is safe to store the address of the array, or if there is a function that changes the data location. For example:

std::array<int, 100> array;
int* startMarker = array.data();
(filing the array and doing operations on it)
std::cout << *startMarker << std::endl;

Thanks for the answers.

Upvotes: 2

Views: 1559

Answers (1)

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

std::array is of static size and the addresses kept for the interned data elements are stable (unlike as with std::vector).

So yes, its safe to keep these addresses.

Upvotes: 8

Related Questions