multi-dimensional array dinamic allocation VERSUS <vector>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roberto Dias

    multi-dimensional array dinamic allocation VERSUS <vector>

    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
  • Paolo Alexis Falcone

    #2
    Re: multi-dimensional array dinamic allocation VERSUS &lt;vector&g t;

    Roberto Dias wrote:
    [color=blue]
    > 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[/color]

    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.
    --


    Paolo Alexis Falcone
    pfalcone@free.n et.ph

    Comment

    Working...