Fixed size data structure

u0206397

Senior Member
Joined
Jul 15, 2009
Messages
764
Reaction score
0
When it comes to dealing with binary data of certain format, in C/C++/C#, there are struct with a predictable layout and size to deal with them.

How do other languages deal with this to define, read and parse binary data easily?

What other popular programming languages have similar feature to declare and define such fixed size data structures?
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
When it comes to dealing with binary data of certain format, in C/C++/C#, there are struct with a predictable layout and size to deal with them.

How do other languages deal with this to define, read and parse binary data easily?

What other popular programming languages have similar feature to declare and define such fixed size data structures?

perl - pack/unpack
pascal - record
java - read/write file streams RandomAccessFile

fixed size structures are rather moot in memory unless you are going to persist them into storage.

Even in dynamic classes like Java, they are still pretty much fixed size, but the sizing is based on serialization and you can determine the order of serialization by overwriting the readObject and writeObject methods, you don't necessarily need to enforce using syntax.

Don't be too caught up with these syntax issues, they are not going to be the determining factor of how low you can go. Besides a lot of higher level programming languages like Python, Perl, Ruby, Java has integration with C/C++ to allow you to reach down into low level constructs conveniently without sacrificing the benefits of highly featured and dynamic higher level programming languages.

You don't construct a house just using a screw driver right? Why then design a solution/program with just one programming language? :)

struct in C/C++ can be packed into a predictable layout for simple record reading and writing. But when you have a linked list implemented in struct, how are you going to persist this piece of information directly? At the end of the day, you as the software engineer has to decide how to persist data

Slightly out of topic, these days, there are approaches like using embedded database to persist data, so file access is not practice by a lot unless interoperability with older data or systems or in embedded system or direct memory access. In those cases, there are preferred mode of how to engage these data. It is not about the programming language at all.
 
Last edited:

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,719
Reaction score
529
Just curious, is the title related to programming efficiency vs storage efficiency ? Just a neophyte question. :s8:
 

u0206397

Senior Member
Joined
Jul 15, 2009
Messages
764
Reaction score
0
Just curious, is the title related to programming efficiency vs storage efficiency ? Just a neophyte question. :s8:

Programming efficiency.

I thought there is a straightforward way to use a one liner code to do such binary data parsing. So checking around for possible faster or easier options.

And yes, if I can avoid those pesky memory management in C/C++, that would be best.
 

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,719
Reaction score
529
In the olden days, storage is very very very expensive. A 1950 fridge size storage device is only good enough for a song now. Of course, storage efficiency is more important then.

RAMAC-EngProtoType-.jpeg
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top