Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the lifetime of memory pointed to typeinfo::name()?

In C++ I can use typeid operator to retrieve the name of any polymorphic class:

const char* name = typeid( CMyClass ).name();

How long will the string pointed to by the returned const char* pointer available to my program?

like image 331
sharptooth Avatar asked Jan 21 '10 13:01

sharptooth


2 Answers

As long as the class with rtti exists. So if you deal with single executable - forever. But for classes in a Dynamic Link Librariy it shifts a little. Potentially you can unload it.

like image 147
Dewfy Avatar answered Nov 15 '22 04:11

Dewfy


The memory returned by type_info::name() will be available for the application's lifetime.

like image 30
sbi Avatar answered Nov 15 '22 06:11

sbi