I would like to use StreamPos[] to seek through a binary file in “Real32” sized chunks.
I can calculate the offset of the data in the stream and move by “Character8” positions.
How do I get the file size of a “Real32” or any other non byte numeric?
In the ‘C’ programming language there is a sizeof() macro for this purpose.
Is there an equivalent function for getting SizeOf[“Real32”] or SizeOf[“Real64”] ?
I had thought of a method using a temorary file to get system sizes of written values.
(ie: write a single value to a temp file and get the size of the file)
This seems like a lot of effort , and overhead, for something that must surely already exist in the language.
The problem with your constant code is that you have now created a scope issue and it’s not extensible. This means that if one used it hidden in a package, and additional types are added to the system, the package would fail with the new types until teh package was reprogrammed.
I’m not sure the issue is as trivial as you expect.
An additional fix for my original code uses a non-file stream. That would eliminate the need to open a file. A memory stream should work just as well.
I can see some advantage in your write-and-find-out approach in case a new and mysterious binary type appears out of somewhere. But you asked why that’s not a built-in function, and these types are not user-extensible in Mathematica. An internal function would also need to be extended if new formats are added to the system, just as the implementation of BinaryRead/Write would need to be extended.
The size for any of the existing binary input/output types is not hidden from you in any way, and I find it unlikely any new hypothetical additions would start obscuring it.
How does sizeof() get implemented in a C compiler, at the lowest level? Well, probably someone reads the architecture-specific ABI documentation, finds an appropriate table of fundamental data type sizes and alignments, and hardcodes these in…