Re:PSD is not my favourite file format (2009)
by rwallace on Thursday January 28, 2021 @03:08PM
(#25948289)
I'm curious, what was the reason for the difference? While the C language standard doesn't guarantee anything about alignment, I'm used to the behavior of compilers in practice being consistently 'align everything on its own size'; what changed between debug and release builds in that case?
Re:PSD is not my favourite file format (2009)
by krylon on Thursday January 28, 2021 @03:41PM
(#25948858)
In the non-debug build, the compiler was free to align structs as it saw fit, in the debug build, it was told to pack them really tight, no padding. Why? The only reason I can think of is to save a few precious bytes of disk space.
Re:PSD is not my favourite file format (2009)
by klodolph on Thursday January 28, 2021 @03:40PM
(#25948846)
Primitives have not historically been aligned to their own size. There are plenty of older systems where double floats had 32-bit alignment instead of 64-bit, or 32-bit integers had 16-bit alignment.
Re:PSD is not my favourite file format (2009)
by ender341341 on Thursday January 28, 2021 @03:34PM
(#25948719)
They mentioned compiler flags, so my guess would be that they were doing something like tightly packing structs in the release build to lower memory usage or something similar.
Re:PSD is not my favourite file format (2009)
by krylon on Friday January 29, 2021 @12:56PM
(#25960218)
Yes, I think that was the main reason.
It was kind if pointless, though, the biggest file I saw in my time there was around 10MB. How much bigger would that have been with padding? Even an overhead of 100% probably would not have had much of a performance impact and saving a few megabytes of disk space or RAM was not a very strong argument at the time any more (roughly 2007 - 2009)
On the other hand, this was a natural outgrowth of the other programmers' tendency to keep it simple and avoid bloat, which all in all I appreciated very much.
Re:PSD is not my favourite file format (2009)
by saagarjha on Thursday January 28, 2021 @03:34PM
(#25948733)
Or the opposite, as packing usually requires slower, unaligned accesses.
Re:PSD is not my favourite file format (2009)
by sumtechguy on Thursday January 28, 2021 @04:11PM
(#25949264)
That would depend on how much that struct is created in memory vs the total code that uses it. If you have one instance in memory then yeah the code is probably bigger and slower (depending on arch). But if you have thousands of the structs in memory the speed and code size trade off may be worth it on a memory constrained system.
Debug also sometimes turns on overrun buffers so you can check for over/under runs in your code at debug time. Some compilers have this others dont.
The compiler flags telling the compiler how to align structs were different for debug and non-debug builds. So, of course, the first thing I did, was to create non-debug build and try to open a file created by a debug-build-executable, the program crashed and burned without giving me a meaningful error message, it took me hours to understand my mistake.
Raw memory dumps are very neat efficiency-wise, but they are extremely fragile.