Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I swapped std::string and std::vector when writing that comment :/ But still, there's no need for a vector to necessarily keep three pointers, it could use a pointer and two sizes for example.


In Rust they call it "three pointers" because a size and a pointer are either both 32 bits or both 64 bits


I’ve never heard this term used, to be honest. The type name is “usize.”


Whether std::vector holds three pointers or a pointer and two sizes is entirely irrelevant. Either way sizeof(vector<T>) does not vary depending on T.


It is extremely relevant when responding to the claim "std::vector consists of three pointers".


Only to pedants. Everyone knows that adding a pointer to a ptrdiff_t calculated from the same array gives you another pointer.

If your real life benchmark heavily penalises this addition (and not the complementary subtraction when computing a size or a capacity) I ask you to volunteer it.


It is not pedantic to reply to "std::vector is three pointers" with "actually, it might use a size instead of a pointer". Replying to "std::vector is often three pointers, or something functionally equivalent" with that would just be wrong. I have not made any claims about performance, but if I was asked to I would say that the difference is likely so minor that it doesn't matter.


It's not simply pedantic, you would be interested in knowing that if you are interested in the implementation of vector-like data structures or if you want to implement one yourself, and the only motivation for that isn't that you are penalized in some benchmark. In article about the details of C++, and especially in a footnote, it's relevant IMO.

It does happen that the only thing the point in the article relies on is `sizeof`, for sure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: