Archived

This topic is now archived and is closed to further replies.

90907

Ooo baby I like it Raw!!!

Recommended Posts

90907    122
This is my third year as a programer ( I started at 16 now i am 19) and in that time i''ve seen alot of data structures - stacks, linked lists, Cob this, Q that - and i understand them pretty well. But why is it that I still think that a Raw array is usually the best thing to use in most applications? Ok so Im still a rookie - but it seems that all the other data structs do more than I want them to do. Dont get me wrong I know when its best to use a stack or even a template container but those are for specific cases. I just dont want to break the law of "Least privilege" by having my lists do more than is needed. Do you agree? Can someone help me sort out my ramblings?

Share this post


Link to post
Share on other sites
Kylotan    9852
Sure, you can do anything with an array, but then you can do anything in assembly language too, if you want.

Scenario 1: If I have a list of things, and I find myself wanting to delete an arbitrary one from that list which might be in the middle, I don''t want to have to shuffle down a few hundred elements to fill up the gap in the middle of the array, or have to check if each element is valid before I do something with it.

Scenario 2: What if I want to store an arbitrary number of items? If I use an array, I either have to allocate more than I''ll ever need (wasteful of resources, not to mention the fact that you will usually underestimate how much you''ll need), or use an dynamic array (more complicated code).

I can think of lots more examples where an array could do the job if I wanted it to, but it makes the code either less efficient (in terms of memory, cpu, or both) and less elegant to do so. When you make your container do less work, that means the rest of your code has to do more work in return, so you don''t really gain anything except less clear code.

Share this post


Link to post
Share on other sites
brad_beveridge    122
Nothing wrong with using arrays, if you get all you need from them with out extra work. Personally I almost always use STL vectors, I never used to - but then one day I had to learn them & haven''t gone back since. But I say, if arrays do the trick, don''t be ashamed to use them (but don''t complain to me if you write a tonne of array specific code & then need to dynamically resize the array!!)

Brad

Share this post


Link to post
Share on other sites
phueppl1    122
I usually use linked lists.. my own implementation ( yes I have a loooot of structs in my programs :o)) I never tried the STL but hey, if I can manage on my own, why try STL, I''m sure my code is faster, at least at running it from front to back :o)

cya,
Phil

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

Share this post


Link to post
Share on other sites