c++ - Dynamic linking, memory usage and concurrency -
when executable links static library, executable contains necessary library parts, used in code, right?
but i'm missing part - how shared objects (the dynamic linked libraries) used exactly?
as far know, not included in executable, dynamically loaded using dlopen
, done directly linker, right?
in case, where's library located in memory? mean, there posts here, explaining dynamic libraries reduce memory usage, how exactly? , if dynamic library somehow loaded shared memory (for several processes), how kernel handles concurrency in case?
i realize fundamental , sorry if duplicate, couldn't find such.
i aware of static linking vs dynamic linking , ask bit different.
the shared library indeed loaded memory shared between "users" (all applications using same library).
this done reference-counting, each new user of library, reference counted up. when application exits, reference count counted down. if gets zero, library no longer needed, , removed memory (quite possibly when "memory needed else", rather "immediately"). reference counting done "atomically" kernel, there no conflict of concurrency.
note it's code in shared library shared. data sections private per process.
Comments
Post a Comment