开发者

C++ stl collections or linked lists

开发者 https://www.devze.com 2022-12-22 20:29 出处:网络
I\'m developing a OpenGL based simulation in C++. I\'m optmizing my code no开发者_如何学编程w and i see throughout the code the frequently use of std:list and std:vector. What is the more performatic:

I'm developing a OpenGL based simulation in C++. I'm optmizing my code no开发者_如何学编程w and i see throughout the code the frequently use of std:list and std:vector. What is the more performatic: to continue using C++ stl data structs or a pointer based linked list? The main operation that involve std::list and std::vector is open a iterator and loop through all items in the data structs and apply some processing


How about stl containers of pointers?

It is highly unlikely that you will be able to develop better performing structures than the builtin. The only down part is the containers actually do contain copies of objects stored in them. If you're worried about this memory overhead (multiple structs hodling multiple copies of same objects, breaking consistency across the table) you should think about using stl structures of pointers to what you need.

Algorithmically speaking, the structure you need is implemented in the stl so you should use it. There is no need to reimplement the same structure.


Use C++ STL data structs, but use them efficiently. If you're using std::list and std::vector, look up such functions as find, for_each, accumulate, etc. Here's some good reading: http://www.cplusplus.com/reference/

Read the sections on algorithm, numeric, and functional. Also, I strongly recommend Scott Meyers' Effective STL.

0

精彩评论

暂无评论...
验证码 换一张
取 消