DRAMsim3
DRAMsim3 copied to clipboard
When put on stack or within struct, `dramsim3::MemorySystem` corrupts memory
Because the class layout given in dramsim3.h and memory_system.h are different (the one given in public interface has no private members, which affects memory layout), when dramsim3::MemorySystem are placed on stack or within other containers, it may corrupts what's placed directly after it.
Notice that in memory_system.h there are two fields, but in dramsim3.h there is not. Is there a reason for this difference?
The problem I met is with std::optional<T>. Its implementation in g++(libstdc++) is basically as followed:
template<typename T>
class optional<T> {
union {
struct {} _empty;
T _data;
}
bool engaged;
};
If T's apparent size is smaller than it's real size, then the mutation within T will affect engaged.