Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Templates and Dynamic Memory Allocation Templates

807575Sep 10 2010 — edited Sep 10 2010
Hi , I was reading a detailed article about templates and I came across the following paragraph

template<class T, size_t N>
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<int, 100> 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.

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...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2010
Added on Sep 10 2010
2 comments
1,102 views