|
I am comparing disk files to see if they are the same. (I don't care about the details, I just want a yes/no result.) Currently, I am loading a pair of byte arrays with System.IO.FileStream.Read() and then comparing them using a for loop. This works, but I was wondering if there is a more efficient way to handle it. The current implementation seems to be pretty slow. (I haven't been able to find the .NET equivalent of "memcmp".)
Also, how much of a factor is the array size? Is it better to read 1KB at a time from a file or 1MB?
Thanks!
|
|
|
|
|
I'd read it in small chunks, unless you know the files will never be huge. Otherwise, they will sit in memory.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
You can use a block of unsafe code, then you can use pointers, and compare the data int by int instead of byte by byte. Then you get more or less what memcmp would do. You have to pin the buffers in memory first, though, so that the garbage collector can't move them.
The buffer size doesn't matter much, unless it's very large or very small. If you create objects that are larger than 85 kB, they will be allocated from the large objects heap. The large objects heap can only grow, it never gives any memory back to the system even if the memory is not used, so you should avoid greating large objects if you can.
---
Year happy = new Year(2007);
|
|
|
|
|
Before loading an entire file, or big chuncks of it, I would suggest:
- to compare file length
- if considered relevant for equality, compare file dates
- then simply compare a few bytes at specific locations (e.g. at offsets 0, 1024, 10240,
length-10240, length-1024, length-1).
- only then perform a systematic comparison.
Of course the sequence should be terminated as soon as a difference has been found.
Luc Pattyn
|
|
|
|
|
I need this registry values to insert.
"ValueName"=hex:fd,d5,72,d6,8b,6a,8a,6f,d5,33,95,fd"
But i only know how to insert a string values.
Help.
Vasildb
|
|
|
|
|
Hello Vasildb,
I think you have to convert your HEX string too int32.
If you have .Net >1.1 you can use Int32.TryParse.
public Int32 HexToInt32(string hexString, Int32 default)
{
Int32 actvalue;
if(Int32.TryParse(hexString, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out actvalue))
{
return actvalue;
}
else
{
return default;
}
}
Int32 actvalue = HexToInt32("fd", 0);
if(actvalue!=null)
{
YourRegKey.SetValue("Name", actvalue);
}
Have not testet it, so I hope it works for you.
All the best,
Martin
|
|
|
|
|
In .NET 1.x you could only read/write strings (REG_SZ entries) in the registry with the managed
classes (RegistryKey). For other entry types (such as REG_DWORD) you had to use PInvoke.
Since .NET 2.0 there is also support for the other entry types, through the new
RegistryValueKind enum, and new methods in RegistryKey class such as RegistryKey.GetValueKind()
Luc Pattyn
|
|
|
|
|
Hello,
I've been retrieving the hidden text from a link (RichTextBox link) using the following:
private int GetFirstHiddenCharacter(int position)
{
this.Select(position, 1);
while (this.SelectionType != RichTextBoxSelectionTypes.Empty)
{
position++;
this.Select(position, 1);
}
return position;
}
then using a substring function to get the rest of the hidden text.
Anyone know of a more elegant way to do this? i.e. without selecting each character.
Thanks.
Abisodun
|
|
|
|
|
Hello,
When I/O performance is slow (because of large file copy or OS deployment via network), my .NET application performs much slower than normal Windows apps like Explorer. It seems that my .NET application needs frequent disk access and does not use any caching. I found this out while running a low-memory virtual machine (like 256MB) and doing a large file copy and then trying to minimize and maximize my .NET application.
How can I improve the performance? Does someone know tips to improve the performance?
Thanks.
|
|
|
|
|
I would start by looking at the CLR assemblage of your application. You should look for boxing/unboxing calls as these are an easy thing to fix performance wise. Let me look around, I got a slide presentation from Tom Fuller on this very issue. A good tool for looking at the clr is Reflector.
Hope this helps.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
If your app needs lots of disk accesses it is likely to be IO bound, not CPU bound.
And yet you see it reacting slowly (or not at all?) to minimize/maximize commands.
Maybe I am misunderstanding what you describe, it sounds to me you are doing disk
operations from within the UI thread and complaining about UI responsiveness.
If so, start using a couple more threads...
Luc Pattyn
|
|
|
|
|
No, My application is not doing any disc activity. But windows is doing that.
I think maybe my problem comes from the background image that i have in my application.
Is there a way to cache it, speed the refresh up or just don't refresh it?
|
|
|
|
|
please be much more specific as to what is going on on your system, and what you
observe. Just a few questions, but incomplete since I dont know your stuff:
large file copy: how large ? how long does it take normally ?
is the large file copy invoked by your app, or is it an independent system activity ?
if by your app, is it invoked by the UI thread ?
between which devices is the copy ?
if not doing large file copy how fast/slow is a form maximize/restore/minimize ?
and with large file copy, how fast then.
What is the complexity of the form, what is special to it, how large is your background
image, is it the form's background, your desktop or what ? where is it stored ?
(should not be a problem if reasonable size = less than 10MB, on a normal local hard disk
that is not otherwise overloaded, and without memory shortage).
What is your memory situation: how much RAM, what is your app's working set, does
it need large objects (over 30 MB each) ?
Are there other anomalies: slow resizing, slow painting, jerky behavior, whatever...
How is CPU load (watch task manager/performance) when things go normal, and when
things go slow.
Luc Pattyn
|
|
|
|
|
Hi people
i have 1 question ! How to edit pascal document from c# !? I have compiler only to edit and compile!!??
Thx
nemanja
|
|
|
|
|
You just want a text editor ? Do you want syntax highlighting and so on ? If so, you need to write a control to do it.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
conemajstor wrote: i have 1 question ! How to edit pascal document from c# !?
Why would you? Just use the pascal IDE (like Delphi) or NotePad. Or download another editor, like NotePad++
|
|
|
|
|
Hello,
I have got a datagrid that I have databound an XML file as the data source, this view correctly and I am able to insert and edit/update/delete the entries as I wish.
I am looking to be able to custom sort the list, with the help of "move up/down arrows" on each row within their own columns in the grid; I am quite new to this and have had no luck with finding any examples.
Could any one point me in the right direction?
Thanks
Bart
|
|
|
|
|
Reading a reply from another read got me wondering what people are using for their unit testing and why. I had always used JUnit and NUnit as I had for a short while worked with java. Coming into .net again I discovered csUnit which will be added to your VS environment. I had not seen this functionality from NUnit.
Just Curious.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
|
Thanks.
I really have not found too many differences in the two testing packages, integration into the IDE was the only big requirement I wanted.
I will have to play with both and see if there are any major differences/advantages/disadvantages.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
I would like to automate testing of a Website writing code in C#,
The idea is to open the browser,navigate to the site,once the page is loaded search for a text box write some stuff in it click a button wait for the page refresh and search a string or an element on the page if so Succeeded else report failure,
Guide me with some method or article describing the procedure how to do it,
|
|
|
|
|
|
Hi all. Please see the following scenario. I have a textbox on my page with ADD button. when i enter some text in textbox and Click ADD, the text will be added in my gridview. so far, so good. Now, If i refresh the page, that record has been inserted again and Gridview will now show two similar records. Please tell me how to deal with it ? whether i have to keep check on textbox or what else ?
|
|
|
|
|
What are you doing in your page load or page init events?
|
|
|
|
|
in page load, i have write:
if (isPostBack == true)
{
if (txtValue.Text == "")
{
// Do Nothing
}
}
The paging size of my grid is set to 3. When i INSERT Record for first time, it shows only one record and on the page refresh, it doesnt insert record again. However, when i insert record for the second time, it insert record on page refresh again. Please tell me how to solve it.
|
|
|
|