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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice