24-bit int

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 1 19:37:08 PDT 2017


On Saturday, 2 September 2017 at 01:19:52 UTC, EntangledQuanta 
wrote:
>
> The whole point is so that there is no wasted space, so if it 
> requires that then it's not a waste of space but a bug.
>
> Audio that is in24 is 3 bytes per sample, not 4. Every 3 bytes 
> are a sample, not every 3 out of 4.
>
> Basically a byte[] cast to a int24 array should be 1/3 the size 
> and every 3 bytes are the same as an int24.
>
> Thanks for pointing this out if it is necessary.

It's not a bug, but a feature. Data structure alignment is 
important for efficient reads, so several languages (D, C, C++, 
Ada, and more) will automatically pad structs so that they can 
maintain specific byte alignments. On a 32-bit system, 4-byte 
boundaries are the default. So a struct with 3 ubytes is going to 
be padded with an extra byte at the end. Telling the compiler to 
align on a 1-byte boundary (essentially disabling alignment) will 
save you space, but will will generally cost you cycles in 
accessing the data.



More information about the Digitalmars-d-learn mailing list