If it's better it means faster or safer? I know that vectors are contignous so I shouldn't worry for real time pointer.
Anyway, second idea looks uglier because of reinterpret_cast stuff. Are they the same?
And the way the value is read, it's better (by better I mean faster in that case) to read by data()+offset or by at(offset)?
What do you think?
Note that the two snippets you posted are not functionally equivalent. *(long*)vecSample.data()+offset is equivalent to (*(long*)vecSample.data()) + offset.
Both versions seem unsafe. The .at() member function does range checking, which might slow things down (but whether that matters depends on the usage).
But in either case a long will occupy more than a single character, which could lead to out-of-bounds access. If you wanted safety you might need to use sizeof(long) as well as vector size() somewhere in the code.
For the code I tested, &vecSample[offset] seemed at least as fast as any of the alternatives, and there was no difference in speed regardless of type of cast - though C++ style is considered safer in general, as the compiler is better able to check the code.