From 5c841a1428f3950b61af5f5af0b702f0c26e15bc Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Sat, 15 Aug 2026 12:09:43 +0200 Subject: [PATCH] feat(furvm): add header to thing data Refs: #62 --- furvm/include/furvm/thing.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/furvm/include/furvm/thing.hpp b/furvm/include/furvm/thing.hpp index 34e2f0b..dd50337 100644 --- a/furvm/include/furvm/thing.hpp +++ b/furvm/include/furvm/thing.hpp @@ -200,6 +200,10 @@ public: std::size_t size; std::byte* data; }; + + struct header { + thing_type type; + }; public: thing() {} @@ -213,7 +217,12 @@ public: : m_type(type), m_size(compute_size(type)), m_allocator(allocator) { if (m_type.type == thing_type::Ref) return; // TODO: Account for alignment - m_data = m_allocator.allocate(m_size); + m_data = m_allocator.allocate(sizeof(header) + m_size); + + header* hdr = reinterpret_cast(m_data); + hdr->type = type; + + m_data += sizeof(header); std::memset(m_data, 0, m_size); } @@ -221,7 +230,8 @@ public: * @brief Destructs a thing. */ ~thing() { - if (m_type.type != thing_type::Ref && m_data != nullptr && m_size > 0) m_allocator.deallocate(m_data, m_size); + if (m_type.type != thing_type::Ref && m_data != nullptr && m_size > 0) + m_allocator.deallocate(m_data - sizeof(header), m_size); } /**