简体   繁体   中英

C++ stl collections or linked lists

I'm developing a OpenGL based simulation in C++. I'm optmizing my code now 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM