Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Invalid Question] How to allocate a nested struct memory exactly like defined
MuratUrsavas last edited by
I have a nested struct which have lots of other structs and enums etc. The implemented total size is 285 bytes and I'm using "#pragma pack (push, 1)" to have a consistent memory alignment. Since this project is closely related to an embedded project, the memory alignment must be preserved.
The problem is, the sizeof(myStruct) looks 29 while debugging. And the actual allocated stack space is also 29 bytes. So while trying to put the raw data coming from the embedded system I'm getting segmentation fault as expected. Because the allocated space is much smaller than the required one.
So any idea what's causing this?
P.S: I can't share the actual struct because of the IP issues. Sorry.
Qt: 5.3.1 Prebuilt with MSVC2013
I'm really dumb :) I've remembered right after posting, that I've used unsigned char to see the actual size. Of course I would see 29 for it because it's overflowed.
So the real problem is. How can I make the memory allocation exactly like the implemented struct? I'm trying to get sub-structs with a simple memcpy().
Sorry to disturb you guys, but my problem is in somewhere else. The allocated memory is exactly like the definition. I tried to delete or report for deletion this tread but had no luck.
But writing down somewhere really helps solving issues :)
If you really want to delete this thread entirely, please send me a PM. Right now, I am closing it. I think some people might also learn from your experience :-)