Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jtsylve's full-sized avatar

Joe Sylve jtsylve

View GitHub Profile
@jtsylve
jtsylve / endian_struct_absl.hpp
Last active February 19, 2020 22:04
More efficient version of endian_struct that supports C++17 but requires abseil
#include <absl/base/internal/endian.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#if __has_include("bit")
#include <bit>
#if defined(__cpp_lib_endian) && __cpp_lib_endian >= 201907
@jtsylve
jtsylve / endian_struct.hpp
Last active February 19, 2020 22:01
Automatically convert on-disk mixed endian types to native
#include <algorithm>
#include <bit>
#include <cstddef>
#include <type_traits>
template <typename T, std::endian endianess,
typename = std::enable_if_t<std::is_scalar_v<T>>>
class endian {
public:
constexpr endian() noexcept = default;
@jtsylve
jtsylve / hardware_destructive_interference_size.hpp
Last active October 31, 2019 17:21
hardware_destructive_interference_size definition that handles compilers that don't support std::hardware_destructive_interference_size
constexpr size_t hardware_destructive_interference_size = []() -> size_t {
#ifdef __cpp_lib_hardware_interference_size
return std::hardware_destructive_interference_size;
#endif
// The following values were taken from those commonly used in Google
// open source projects as defined with their CACHELINE_SIZE macro
#if defined(__i386__) || defined(__x86_64__)
return 64;
@jtsylve
jtsylve / modern_hiber_headers.md
Last active February 2, 2017 17:21
Modern Windows Hibernation File Headers
// Windows 8 x86
         typedef struct _PO_MEMORY_IMAGE                   // 38 elements, 0x2C8 bytes (sizeof) 
          {                                                                                      
/*0x000*/     ULONG32      Signature;                                                            
/*0x004*/     ULONG32      ImageType;                                                            
/*0x008*/     ULONG32      CheckSum;                                                             
/*0x00C*/     ULONG32      LengthSelf;                                                           
/*0x010*/     ULONG32      PageSelf;                                                             
/*0x014*/     ULONG32      PageSize;                                                             

Keybase proof

I hereby claim:

  • I am jtsylve on github.
  • I am jtsylve (https://keybase.io/jtsylve) on keybase.
  • I have a public key ASDBDxRhrul5aq-HlsONvkiZbC88rk-JPfmiywDjD6m4mQo

To claim this, I am signing this object: