Feeds

Binary interfaces in component development

A template class with static data - how can that possibly go wrong?

Secure remote control for conventional and virtual desktops

As we know, with few exceptions, a C++ compiler instantiates a template whenever it is specialised, and the template definitions are available (see the ISO C++ standard paragraph 14.7.1). In our code, the template definitions are in the header file so the template definitions are always available. This means that each cpp file that uses the template will contain instantiated definitions of the static object in the compiled object file. When object files are linked, the linker notices that there are many definitions of a single symbol and it merges all definitions into a single definition. Such symbols are marked in the object file as “weak”, so that the linker will unify multiple definitions instead of complaining about a multiply-defined symbol. A counter example of a “strong” symbol is a non-inline function definition; here the linker would give an error if it came across a duplicate definition.

When these definitions all occur in a single monolithic binary, there are no problems. This is shown by the following example, where we introduce a singleton class that we implement via our GenericSingleton template. If the implementation works correctly then this object will be constructed and destructed only once. To test our singleton we add two further cpp files containing code that uses the resulting singleton, and a further cpp containing the main function. In our initial test, we run it as a monolithic binary and we expect that only a single singleton object will be constructed – see Figure 1.

Figure 1: Shows that everything is OK when we're building statically.

The above is the case where our binary is linked monolithically, using only static libraries and everything works. Now, imagine a scenario where your manager wants to decompose the project, so that different project teams can be responsible for their own dynamic library, so that development can occur in parallel, so that functionalities can be unit tested without rebuilding everything - and for all the other reasons that motivate people to use dynamic libraries. This manager, like lots of people, comes from a planet where an application can be built interchangeably, either statically or dynamically, with no difference in behaviour.

I’m sure we’d all like to come from this programmer’s paradise too, but until we can find a way to move there, maybe we’ll have to support our user base here on Earth with its less than perfect operating systems. So, what will happen when we take our simple program and change it from a monolithic binary into a set of dynamically-linked components?

Intelligent flash storage arrays

More from The Register

next story
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
You stupid BRICK! PCs running Avast AV can't handle Windows fixes
Fix issued, fingers pointed, forums in flames
NSA SOURCE CODE LEAK: Information slurp tools to appear online
Now you can run your own intelligence agency
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
prev story

Whitepapers

Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
Designing and building an open ITOA architecture
Learn about a new IT data taxonomy defined by the four data sources of IT visibility: wire, machine, agent, and synthetic data sets.
How to determine if cloud backup is right for your servers
Two key factors, technical feasibility and TCO economics, that backup and IT operations managers should consider when assessing cloud backup.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.