From 5407a099d3e80370c5fa67358582966a7b035f11 Mon Sep 17 00:00:00 2001
From: Beman
Which approach to endianness is best depends on the interaction between -approach characteristics and -application needs.
+The best approach to endianness depends on interaction between +the approach characteristics and +the application needs.
+ +The characteristics that differentiate the approaches are the endianness invariants, conversion explicitness, arithmetic operations, sizes available, and alignment requirements.
-@@ -194,7 +197,7 @@ That makes these types easy to use and programs easy to maintain.-
@@ -208,7 +211,7 @@ to hoist conversions out of inner loops can bring a performance penalty.-
@@ -225,7 +228,7 @@ are very easy to use if lots of arithmetic is involved.-
@@ -238,7 +241,7 @@ factor, using sizes tailored to application needs can be useful.-
@@ -267,6 +270,48 @@ needed they are often very useful and workarounds are painful. For example,+
An existing large codebase runs on little-endian Linux systems. It already +deals with endianness via +Linux provided +functions. Because of a business merger, the codebase has to be quickly +modified for Windows and possibly other operating systems, while still +supporting Linux. The codebase is reliable and the programmers are all +well-aware of endian issues.
+ +These factors all argue for an endian conversion
+approach that just mechanically changes the calls to htobe32
,
+etc. to boost::endian::native_to_big
, etc. and replaces <endian.h>
+with <boost/endian/conversion.hpp>
.
A new, complex, multi-threaded application is to be developed that must run +on little endian machines, but do big endian network I/O. The developers believe +computational speed for endian variable is critical but have seen numerous bugs +result from inability to reason about endian conversion state. They are also +worried that future maintenance changes could inadvertently introduce a lot of +slow conversions if full-blown endian arithmetic types are used.
+ +The endian buffers approach is made-to-order for +this use case.
+ +A new, complex, multi-threaded application is to be developed that must run +on little endian machines, but do big endian network I/O. The developers believe +computational speed for endian variables is not critical but have seen +numerous bugs result from inability to reason about endian conversion state. +They are also concerned about ease-of-use both during development and long-term +maintenance.
+ +Removing concern about conversion speed and adding concern about ease-of-use +tips the balance strongly in favor the endian +arithmetic approach.
+Supply compilers, including GCC, Clang, and Visual C++, supply built-in support for byte swapping intrinsics. The library uses these intrinsics when available since they may result in smaller and faster generated code, particularly for release