std::function and shared object libraries

Nick nospam@codesniffer.com
Tue Jun 16 23:58:00 GMT 2015


On Tue, 2015-06-16 at 08:01 -0500, johnsfine@verizon.net wrote:
> An object of a templated type might be allocated at run time in the single heap shared by both the main module and the .so.  But the type itself is instantiated at compile time and ends up being in one place or the other (main image or .so) depending on exactly how things are coded.

Apologies, seems like I've caused confusion by not clearly separating
the terms.  By "instantiating" I was referring to the run-time instance
of std::function--ie. the object.  I overlooked that a template also has
an 'instance' produced by the compiler for a given type(s).

The code for the template will reside in the module that it was compiled
into, and as a result is only available while the module is loaded.  The
object(s) of that type will reside in the process' memory and so will
remain until removed, though accessing them will not be possible if the
corresponding code is gone (as would happen when the module is
unloaded).

I think I'm clear now, thanks.




More information about the Gcc-help mailing list