From aba665ec9a74483cdbab3e49ef62c30621934c09 Mon Sep 17 00:00:00 2001 From: Grigorii Sokolov Date: Tue, 25 Feb 2025 16:14:47 +0200 Subject: [PATCH] reduce memory footprint - members of classes rearrangement --- med/bit_string.hpp | 8 ++++---- med/field.hpp | 6 +++--- med/octet_string.hpp | 2 +- med/value.hpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/med/bit_string.hpp b/med/bit_string.hpp index da45b8c..6366286 100644 --- a/med/bit_string.hpp +++ b/med/bit_string.hpp @@ -75,14 +75,14 @@ class bits_variable m_least_bits = calc_least_bits(std::size_t(num_bits)); } - uint16_t m_num_bytes {0}; - uint8_t m_least_bits {0}; //0 - not set, or 1..8 - union { uint8_t const* external {nullptr}; uint8_t internal[sizeof(uint64_t)]; } m_data; + + uint16_t m_num_bytes {0}; + uint8_t m_least_bits {0}; //0 - not set, or 1..8 }; //fixed length bits @@ -141,8 +141,8 @@ class bits_fixed } private: - bool m_set {false}; uint8_t m_data[size()]; + bool m_set {false}; }; template diff --git a/med/field.hpp b/med/field.hpp index d1bfc59..93df843 100644 --- a/med/field.hpp +++ b/med/field.hpp @@ -68,8 +68,8 @@ class multi_field : public detail::define_meta_info struct field_value { - field_type value; field_value* next; + field_type value; }; static constexpr std::size_t min = MIN; @@ -239,10 +239,10 @@ class multi_field : public detail::define_meta_info return &m_tail->value; } - field_value m_fields[inplace]; - std::size_t m_count {0}; field_value* m_head {nullptr}; field_value* m_tail {nullptr}; + std::size_t m_count {0}; + field_value m_fields[inplace]; }; } //end: namespace med diff --git a/med/octet_string.hpp b/med/octet_string.hpp index 01e4100..f78747a 100644 --- a/med/octet_string.hpp +++ b/med/octet_string.hpp @@ -99,9 +99,9 @@ class octets_var_intern } private: - uint8_t m_data[MAX_LEN]; num_octs_t m_size {0}; bool m_is_set {false}; + uint8_t m_data[MAX_LEN]; }; //fixed length octets with external storage diff --git a/med/value.hpp b/med/value.hpp index 1e6df93..c169062 100644 --- a/med/value.hpp +++ b/med/value.hpp @@ -83,8 +83,8 @@ struct numeric_value : IE #endif private: - bool m_set{false}; value_type m_value{}; + bool m_set{false}; }; /**