Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Informal Poll : Favorite STL container

This thread is locked; no one can reply to it. rss feed Print
Informal Poll : Favorite STL container
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

torhu
Member #2,727
September 2002
avatar

jmasterx
Member #11,410
October 2009

Nobody has said why >:(

I will also say vector.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Eric Johnson
Member #14,841
January 2013
avatar

I'll also go with vector. It's just so convenient.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

torhu
Member #2,727
September 2002
avatar

Some useful ones added in C++11:

std::unordered_map, std::unordered_set, and std::array.

Chris Katko
Member #1,881
January 2002
avatar

This is like asking whether you prefer a philips or blade screwdriver. ??? You use the right one for the job.

{"name":"617lkr02DDL._SL1500_.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/4\/449c9949305b067d4f0bafb8ccd6dfd4.jpg","w":1500,"h":923,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/4\/449c9949305b067d4f0bafb8ccd6dfd4"}617lkr02DDL._SL1500_.jpg

And if in doubt, shove it in the socket and turn:

{"name":"15789.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3e8cd8a398f348c00e05eac31c1c0b23.jpg","w":1278,"h":849,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/e\/3e8cd8a398f348c00e05eac31c1c0b23"}15789.jpg

I will admit that I almost never use trees because my work has never needed them. Most business (and 2-d game stuff) ends up being either vectors or associated maps. So I have no deep experience with them as I rarely need to solve a "tree" problem.

I do LOVE quadtrees though. Spatial data structures make so much more intuitive sense for me. And BSP's are neat although, IIRC, you can't modify them easily so it goes tits-up if you want to say, have, a dynamic world represented in a BSP tree. Then again, Quake couldn't do it because of BSP's... but... Unreal Tournament could and they used BSPs... I wonder what they did to improve it? Then again, it still wasn't "that" dynamic. Moving platforms, rotating is different than say, Duke Nukem 3D with entire buildings collapsing while you play.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Peter Hull
Member #1,136
March 2001

I found the answer using Science:

$ find . -name "*.cc" -exec grep "vector" '{}' + |wc
     163     620   10133
$ find . -name "*.cc" -exec grep "list" '{}' + |wc
     130     820    9985
$ find . -name "*.cc" -exec grep "map" '{}' + |wc
     699    3389   43498
$ find . -name "*.cc" -exec grep "deque" '{}' + |wc
       0       0       0
$ find . -name "*.cc" -exec grep "set" '{}' + |wc
     965    6089   63995

:-/

MiquelFire
Member #3,110
January 2003
avatar

I took a flowchart someone posted here once and made a JS thing to allow me to pick the right one.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

SiegeLord
Member #7,827
October 2006
avatar

std::vector. Contiguous memory, cache friendly, nice API, faster than all other containers for small lengths (and not so small in case of the worst container, std::list). It's the perfect container.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I found the answer using Science:

$ find . -name "*.cc" -exec grep "vector" '{}' + |wc
     163     620   10133
$ find . -name "*.cc" -exec grep "list" '{}' + |wc
     130     820    9985
$ find . -name "*.cc" -exec grep "map" '{}' + |wc
     699    3389   43498
$ find . -name "*.cc" -exec grep "deque" '{}' + |wc
       0       0       0
$ find . -name "*.cc" -exec grep "set" '{}' + |wc
     965    6089   63995

Oh Peter, you really should give deque a try. Trust me, find a reason to use it and you'll love it.

Surprisingly here, no one has mentioned a heap. :O

bamccaig
Member #7,536
July 2006
avatar

Link in my signature to the flowchart (not my creation).

I have no favorite container. >:( Also, I haven't been programming C++ much lately.

relpatseht
Member #5,034
September 2004
avatar

Vectors and deques, but I rarely use the STL.

Spatial trees are essential for games. Steer clear of BSP trees. They haven't been relevant in decades. Quadtrees make sense, but you're better off generalizing to an r-tree. You'll probably get the best perf via an 8 wide OBB tree, traversed/queried via AVX. I find k-means to be a great bulk loading strategy.

Go to: