|
Thank you both
I will so write my own one because I need an equivalent to memcmp, not returning a bool but an integer telling who is greater
|
|
|
|
|
Hello
I need to use a BinaryReader to read strings but I want to know how to prepare string in my file
This is to documentation comment :
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time
Does it mean that a string can't be longer than 127 bytes (7 bits integer) ??
|
|
|
|
|
I use the following method to read files. Its pretty fast and then you could use regular expressions to find text within the returned string or what ever else you need to do with the content.
<br />
public string DecodeFile(string fullpath)<br />
{<br />
if (File.Exists(fullpath) == false)<br />
throw new FileNotFoundException();<br />
<br />
try<br />
{<br />
FileStream fStream = File.OpenRead(fullpath);<br />
byte[] buffer = new byte[fStream.Length];<br />
int bytesRead;<br />
bytesRead = fStream.Read(buffer, 0, buffer.Length);<br />
fStream.Close();<br />
fStream.Dispose();<br />
<br />
if (bytesRead <= 0)<br />
throw new Exception("Empty file.");<br />
<br />
Decoder decoder = Encoding.Default.GetDecoder();<br />
char[] cBuffer = new char[buffer.Length];<br />
<br />
int bytesConverted, charsConverted;<br />
bool bCompleted;<br />
<br />
decoder.Convert(buffer, 0, buffer.Length, cBuffer, 0, buffer.Length, false, out bytesConverted, out charsConverted, out bCompleted);<br />
return new String(cBuffer, 0, bytesConverted);<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(ex.Message);<br />
}<br />
<br />
}<br />
Google search lead me to this info
"Well, its not quite that simple. int.MaxValue is the most the string class
itself could handle, you are right, but since characters take up two bytes,
that many characters would go way beyond the max possible allocation. The
best theoretical high value is 2^31(or 2147483648) characters, since that is
exactly how many would fit in memory. Practially it'd be much, much smaller."
http://bytes.com/forum/thread481655.html[^]
Just because we can; does not mean we should.
|
|
|
|
|
Hello
This can be good for little file but if you have to manage a few very big files it does not seems to be a good approach
And it does not give me the answer to my question : what is 7 bits encoded integer. Does it limit string lenght to 127 bytes ?
|
|
|
|
|
Take a look at the BinaryReader.Read7BitEncodedInt, BinaryWriter.Write7BitEncodedInt.
The 7 bits integer means that a 32 or 64 bit int can be written in a single byte if the value of the int does not exceeds 7bit (127 decimal). This is done to save space, i.e. an int instead of 4 or 8 bytes may be saved in a single byte.
|
|
|
|
|
Thank you
Finaly thank to you I've found on internet how to build an 7 bit encoded integer !
|
|
|
|
|
I work with a guy that is always talking about how many flops[^] a particular activity takes. Quoting him directly HOWEVER, when passing the information from method to method, an arraylist is not the most efficient taking up to 60,000 flops to pass the information therefore arrays are faster. I asked him once where he got this information and was told that somebody at Microsoft told him. Does anybody know where there is any written documentation about this? I would like to learn more about this to become a more efficient coder. References to information would be very helpful. I have Googled for this info and not found it, so any help is appreciated.
Hogan
|
|
|
|
|
With the risk of going completely out of line here ( forgive me if I do ) , but I think the term 'flop' is something that this particular engineer dreamed up himself. I've never encountered nor heard of 'flops' when parsing information.
What's more .. the engineer contradicts himself by say that arraylist is not the most efficient and a bit further up therefore arrays are faster Faster to what ?
Cheers
|
|
|
|
|
I believe he is referring to the term I linked to in my first article.
Hogan
|
|
|
|
|
Flops refers to the number of FLoating point Operations Per Second.
|
|
|
|
|
Have you tested it by collecting the DateTime before the method and the DateTime afterwards and then calculating the difference to see what is actually faster? I know your looking for documentation, but never throw out good old fashioned testing.
Just because we can; does not mean we should.
|
|
|
|
|
Yeah, I've done tests... Proved the exact opposite. But he wouldn't even look at my test program to see the results. I was hoping for more data... Not that it would be read.
Hogan
|
|
|
|
|
Wow. He's trying to hide his complete ignorance by dropping buzzwords on people. Measuring the speed of an activity in FLOPS is like measuring the speed of a car in liters of Gas per hour.
|
|
|
|
|
That is a proven tactic when you're absolutely clueless about what you are doing.
A skill commonly found in managers s
|
|
|
|
|
Dave Kreskowiak wrote: Measuring the speed of an activity in FLOPS is like measuring the speed of a car in liters of Gas per hour.
Now you cause me to doubt my comprehension of this. FLOPS would be specific and consistent on the particular system yes? So doesn't work for the OPs statement since ArrayList processing is going to run at the same per second rate as anything else on that system, yes? However a car operates at a variable rate of speed so, my head esplode like a liter of Gas!
led mike
|
|
|
|
|
ignorance == incompetence?
|
|
|
|
|
I'm also having problems comprehending how much floating point arithmetic .Net needs to copy memory.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
I'm also having problems comprehending how much floating point arithmetic .Net needs to perform to copy an 8 byte pointer
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
I'm also having problems comprehending how much floating point arithmetic .Net needs to perform to copy a pointer
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Crud, it kept timing out
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
when passing the information from method to method, an arraylist is not the most efficient taking up to 60,000 flops to pass the information therefore arrays are faster.
That's not only wrong, it's also wrong.
When passing information to a method, it takes exactly the same time to pass an Array as an ArrayList. They are both objects, so what you pass to the method is a reference to the object. A reference is just a pointer, so on a 32 bit system it's only four bytes to copy.
Whatever you do with an ArrayList, there are no floating point operations going on. You could say that an operation would use the equivalent of 60000 flops, but it's hardly useful to measure operations that doesn't use floating point operations in flops.
Also, there are so much more to consider than the raw processor load. You have so many other factors that affect the performance, like cache sizes, memory bandwidth, data bus width, data aligning, instruction pairing... And there are also other things to consider than just performance, like robustness and scalability.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I think I made the same point, errr, 4 times
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
I created a bitmap object and used it to draw a 2D terrain programatically on a form. Then I also added a picturebox control to display an image near the terrain.
However, the picturebox control is blocking out part of the bitmap.
How do I make the bitmap "cover" part of the picturebox control instead?
Is there a "layers" method which the form can use to draw one bitmap over another control?
Edit/Delete Message
|
|
|
|
|
If by saying "the picturebox control is blocking out part of the bitmap." you mean it shows some of the picture then set the picturebox control's (Image I think) property to Stretch.
|
|
|
|
|
Drawing an image to the form itself will always place the image behind the controls.
Just because we can; does not mean we should.
|
|
|
|