Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

vectors in c++ and arrays in c

Status
Not open for further replies.

sagar474

Full Member level 5
Joined
Oct 18, 2009
Messages
285
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,318
Location
India,kakinada
Activity points
3,122
are the vectors in c++ are expansive and time consuming compared to arrays in c?
 

Hi sagar

Arrays are not faster than vectors. Vectors are fully compatible with arrays. There is, however, an overhead in memory usage - which does matter if and only if you have very very many vectors. Vectors are recommended as the substitution for C-style arrays - use them as such. (One simple reason is that you will, at some point, realize that you need to know the size of your array. Then you are screwed if you didn't use vectors in the first place. Another reason is the clean way of handling all containers in the same way - when using a vector::const_iterator it is written in exactly the same way as a list::const_iterator, but for an array things are different. So when changing the container type, you can either change all your source code, or just the container, if you were using a vector and it's common interface. In short, preferring vectors over arrays gives you many advantages for very little extra (memory) cost)...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top