dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: Beginner
Jul 11, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Dynamic Templated Objects

Question:
How does the compiler handle dynamically allocated templated objects? As I have read, the compiler generates code for templated objects and functions according to the required data type.

Answer:
A template class specialization (i.e., a template instance) is defined at compile time. Its code is generated on demand. For example:

std::vector  vi; // generate a vector of int

The compiler isn't responsible for dynamic allocation; it's the runtime environment (usually the OS kernel) that handles the allocation request at runtime, when operator new (or new[] for arrays) is invoked. Thus, when programmers allocate a template object, they allocate an object that already exists; the code for the template instance is generated at compile time, before the allocation takes place. In other words, allocating a template instance is just like allocating any other object.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date