سؤال

I am pretty new to C# and WPF architecture. I have a BinaryFile class in my project which has the following properties: fileName, fileLength, errorCount and dataContent. This class is bound to a Richtextbox. I need to include a property to this class which holds the data in the Richtextbox. Is it a good idea to use a string? My binary files are very huge, on an average 10MB.

هل كانت مفيدة؟

المحلول

From the documentation (bold text bolded by me, not in the source)

A string is a sequential collection of Unicode characters that is used to represent text. A String object is a sequential collection of System.Char objects that represent a string. The value of the String object is the content of the sequential collection, and that value is immutable (that is, it is read-only). For more information about the immutability of strings, see the Immutability and the StringBuilder class section later in this topic. The maximum size of a String object in memory is 2 GB, or about 1 billion characters.

نصائح أخرى

10MB is no problem. The built in limit for a .NET string is 2,147,483,647. However, given that characters in .NET are encoded as unicode, it takes 2 bytes per character, thus cutting that in half. Either way, your 10MB is a long way away from the max.

A string can be 2,147,483,647 characters long.

Note that using many strings may result in OutOfMemoryException. Objects larger than 85000 bytes are large objects and .NET handles them different than other garbage collected stuff. You might suffer from memory fragmentation.

Strings cannot have more than 2,147,483,648 AKA 2^31 characters, since String.Length is a 32-bit integer.

They're also limited by available memory.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top