1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question about Templates

Discussion in 'MFC' started by silver_boy, Sep 10, 2010.

  1. silver_boy

    silver_boy New Member

    Joined:
    Sep 10, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi , I was reading a detailed article about templates and I came across the following paragraph

    template
    class Stack
    {
    T data[N]; // Fixed capacity is N
    size_t count;
    public:
    void push(const T& t);
    };


    "You must provide a compile-time constant value for the parameter N when you request an instance of this template, such as Stack myFixedStack;
    Because the value of N is known at compile time, the underlying array (data) can be placed on the run time stack instead of on the free store.This can improve runtime performance by avoiding the overhead associated with dynamic memory allocation.

    Question:
    Now in the above paragraph what does
    "This can improve runtime performance by avoiding the overhead associated with dynamic memory allocation." mean ?? What does template over head mean ??
    I am a bit puzzled and i would really appreciate it if some one could explain to me what this sentence means thanks...
     

Share This Page