I have been using std::vector
a lot, and recently I asked myself this question: "How is std::vector
implemented?"
I had two alternatives:
1) Linked list, and then making the API feel like random access (i.e. overloading operator[]
).
2) Using new
, e.g. Foo* temp = new Foo[20]
: I believe they do something like this, but then it raises one more question. Do they always allocate a maximum (uint32_t
) storage to give random access? (This is inefficient in terms of memory.)
Or is there something else that I should be aware of?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…