Advertisement Jump to content
Sign in to follow this  

[.net] Managed loading of data

This topic is 4994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am writing a Quake 3 BSP loader in C# and am wondering how to handle the loading of data form the file. In C++ I would do something like this:
struct BSPHeader {
  char Magic[4];
  int  Version;


BSPHeader header;
read( (char*)&header, 0, sizeof(BSPHeader) );

The data fields of the struct are filled in automatically. So my question is now, what is the way to go with managed types in C#. Maybe this:
struct BSPHeader {
  char[] Magic;
  int Version;

BSPHeader header;
header.Magic = new char[4];
char[] buffer = new char[8];
read( buffer, 0, buffer.length );

header.Magic[0] = buffer[0];
header.Magic[1] = buffer[1];

That doesn't seem very elegant, because I have to compute the size of the header manually and have to copy the data manually into the actual header struct. Is there a better solution to this problem? Thanks, Constantin

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!