Hi I am trying to make a custom compiler in my current project, specifically I am trying to add a fixed-size field as header to store some metadata about the object for all types. I was thinking custom allocator trait but gave up later as I may also need stack objects to have this field. I am trying modifying the constructor function of struct std::alloc::Layout to return a layout including this field but I kept encountering crashes in this way. I am wondering in higher level is my approach efficient or there are any other solutions? Thanks in advance!
It definitely isn't possible to do this for all types, because it will break anything with a layout guarantee, such as:
- primitive integer types
- null pointer representation of
[T](slices, which are made up of only their elements)
You would have to apply this change only to types using the default representation.