multi-dimensional array dinamic allocation VERSUS <vector>

R

Roberto Dias

I'm a newbie in C++ programming. I bought a book yet and I have
learned by means internet donwloadble materials. I feel not
confortable using multi-dimensional arrays. I simply cannot understand
memory allocation principle. I have got some ideas that require this
one, but only thoughts and no action I have done. Unfortunately, the
Deitel book don't explore this topic well. Vectors? How to use them
insted of multi-dimensional arrays? What benefit do they bring to the
source code? Could you help me on this topics?

thanks,

Roberto Dias
 
P

Paolo Alexis Falcone

Roberto said:
I'm a newbie in C++ programming. I bought a book yet and I have
learned by means internet donwloadble materials. I feel not
confortable using multi-dimensional arrays. I simply cannot understand
memory allocation principle. I have got some ideas that require this
one, but only thoughts and no action I have done. Unfortunately, the
Deitel book don't explore this topic well. Vectors? How to use them
insted of multi-dimensional arrays? What benefit do they bring to the
source code? Could you help me on this topics?

thanks,

Roberto Dias

C and C++ requires the programmer to manually manage memory allocation
issues (there's no automated garbage collection mechanism unlike in Java or
Python...). Case in point - if you're to use a list of objects that would
change its size on runtime you'd need to allocate memory for object
creation - then destroy them properly upon termination of the program -
else the memory allocated for the said data structure would not be freed. A
knowledge of how pointers work would be needed here.

Vectors are similar to arrays, except that the size of the container isn't
constrained by the declaration. Since it is a standard container class, the
properties of a vector can be manipulated by using the container algorithms
as defined in the STL.

Bjarne Stroustrup's "The C++ Programming Language" discusses much on C++
programming - and is imho a must-have for C++ programmers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top