Read binary file into a struct

The problem is the strings in your struct. I found that marshaling types like byte/short/int is not a problem; but when you need to marshal into a complex type such as a string, you need your struct to explicitly mimic an unmanaged type. You can do this with the MarshalAs attrib. For your example, the … Read more

Locking binary files using git version control system

Subversion has locks, and they aren’t just advisory. They can be enforced using the svn:needs-lock attribute (but can also be deliberately broken if necessary). It’s the right solution for managing non-mergeable files. The company I work for stores just about everything in Subversion, and uses svn:needs-lock for all non-mergeable files. I disagree with “locks are … Read more

How to read a binary file into a vector of unsigned chars

When testing for performance, I would include a test case for: std::vector<BYTE> readFile(const char* filename) { // open the file: std::ifstream file(filename, std::ios::binary); // Stop eating new lines in binary mode!!! file.unsetf(std::ios::skipws); // get its size: std::streampos fileSize; file.seekg(0, std::ios::end); fileSize = file.tellg(); file.seekg(0, std::ios::beg); // reserve capacity std::vector<BYTE> vec; vec.reserve(fileSize); // read the data: … Read more

What is the best place for storing uploaded images, SQL database or disk file system? [closed]

I generally store files on the file-system, since that’s what its there for, though there are exceptions. For files, the file-system is the most flexible and performant solution (usually). There are a few problems with storing files on a database – files are generally much larger than your average row – result-sets containing many large … Read more