0

I'm working on a class for managing STFS files, and some of the data I need is hundreds of bytes long. I'm wondering if there's anything wrong with creating a byte array with that information in the source code instead of reading it from a file. Like doing:

byte[] data = new byte[0x100]{0x23,0x55,0xFF...

I would think that you're creating a byte array no matter what you do, but I've never seen any code like that, so I thought it might be wrong, or not done for readability purposes.

4
  • What are STFS files? Is your data object something like a header? Are you going to create or modify them? Commented Dec 25, 2011 at 5:29
  • Modify them. They are the file system for xbox 360. Commented Dec 25, 2011 at 5:30
  • For what do you need the byte array? Validation? Commented Dec 25, 2011 at 5:32
  • Yeah, something along those lines. Commented Dec 25, 2011 at 5:47

2 Answers 2

1

If it is about validation (e.g., headers) of files you read, then I think it is okay, to declare the values in a byte array. But be sure, that you have only one instance of that in your whole application.

For instance:

static class STFSValidation
{
     public static readonly byte[] Header = new byte[] { ... };
}
Sign up to request clarification or add additional context in comments.

Comments

1

It is ok if data is relatively small and will not ever change (ever = singnificantly less often then source code).

Conisder following when making the decision:

  • do you need to comment data in the source (i.e. magicHeader[3]=42;// the answer).
  • is it relatively small (I'd say 256 entries is max)
  • does it ever change (i.e. signatures for existing file formats GIF - 0x47,0x49, 0x46, 0x38, 0x37, 0x61 are essentially set in stone and will not ever change - see more on magic numbers in http://en.wikipedia.org/wiki/Magic_number_(programming)# )

For large constant blobs embedding into an application as a resource may be better approach.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.