|
Robert Surtees wrote: If I just reverse the order of the tests I get opposite results.
That was my experience as well.
Robert Surtees wrote: The optimizer seems pretty stupid however. Changing
*p = 1.0f;
p++;
to
*p++ = 1.0f
nearly halves the result. Perhaps there is some switch to improve that sort of thing.
Wow. I changed to *p++ = 1.0f and noticed an appreciable difference between the pointer method and the array method.
I have to say though that...
*p++ = 1.0f;
...makes the old C programmer in me cringe. But if it's that much faster...
|
|
|
|
|
Robert Surtees wrote: The optimizer seems pretty stupid however. Changing
*p = 1.0f;
p++;
to
*p++ = 1.0f
nearly halves the result. Perhaps there is some switch to improve that sort of thing.
Are you compiling in release mode, and not debug mode?
In that case it's a bit surprising.
---
single minded; short sighted; long gone;
|
|
|
|
|
I'm pretty sure it was a release build but I'm a bit of a rookie at VS so I'm next to positive I did something wrong and running in debug would for sure mess up the results. I can't imagine why else it would be different.
|
|
|
|
|
Well, the resulting code is a bit different, even in release mode.
The C# code:
*p = 42;
p++; vs.
*p++ = 42;
The IL code:
ldloc.1
ldc.i4.s 0x2a
stind.i4
ldloc.1
ldc.i4.4
conv.i
add
stloc.1 vs.
ldloc.1
dup
ldc.i4.4
conv.i
add
stloc.1
ldc.i4.s 0x2a
stind.i4
The generated code:
mov dword ptr [ebx],2Ah
add ebx,4 vs.
mov edi,ebx
add ebx,4
mov dword ptr [edi],2Ah
I guess that the second code may be faster as the add and mov can be executed in parallell. In the first code the add has to wait for the move, as they use the same register.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi Leslie,
This is related to the formatting, not the topic, of your message.
I am preparing an article on copying code snippets from a CodeProject message board to
Visual Studio; seems there are no problems when the browser used is FireFox, Safari, ...
but often problems arise when using Internet Explorer.
One of the factors is the tags that are present inside the < PRE> </PRE> block.
In your message the lines are separated by <br> tags; most other messages have
just regular newlines.
Could you please tell me how you get that, i.e. what tools you use, and how you go
about it. Thanks in advance.
|
|
|
|
|
Luc Pattyn wrote: One of the factors is the tags that are present inside the < PRE> </PRE> block.
In your message the lines are separated by <br> tags; most other messages have
just regular newlines.
Could you please tell me how you get that, i.e. what tools you use, and how you go
about it. Thanks in advance.
The only thing I do differently is add a space to blank lines. I noticed in IE that if you simply copy code from VS and paste it into a message here at Code Project, blank lines are ignored. I pointed this out on the Suggestions message board, and someone showed me that by adding a space to the blank line, IE will added a break.
So instead of this:
fixed(float* pSource = data)
{
float* p = pSource;
for(int i = 0; i < Size; i++)
{
*p = 1.0f;
p++;
}
}
I add a space to the blank line to get this:
fixed(float* pSource = data)
{
float* p = pSource;
for(int i = 0; i < Size; i++)
{
*p = 1.0f;
p++;
}
}
[EDIT]As far as the tools I use, I just copy code out of Visual C# 2005 edition.[/EDIT]
|
|
|
|
|
Yep, but you walked around what I really wanted to know:
which browser do you use for posting CP messages that include code snippets ?
and do you add any tags inside the PRE tags, such as CODE, BR, other ?
TIA
|
|
|
|
|
Luc Pattyn wrote: Yep, but you walked around what I really wanted to know:
which browser do you use for posting CP messages that include code snippets ?
and do you add any tags inside the PRE tags, such as CODE, BR, other ?
I use IE7. I don't add any tags inside the PRE tag.
|
|
|
|
|
OK, thanks. So I still need to figure out why your snippets are harder to copy
wiht formatting than most others... (that's with IE6/IE7 towards Visual Studio).
|
|
|
|
|
Luc Pattyn wrote: So I still need to figure out why your snippets are harder to copy
wiht formatting than most others... (that's with IE6/IE7 towards Visual Studio).
I'm posting this from Firefox. Let me know if the code below has any additional tags added.
fixed(float* pSource = data)
{
float* p = pSource;
pointerWatch.Start();
for(int i = 0; i < Size; i++)
{
p[i] = 1.0f;
}
pointerWatch.Stop();
}
I'm posting this on the off chance that something in my preferences in Visual C# Express could be embedding html tags.
|
|
|
|
|
Hi Leslie,
there is not really a difference
for both of them, and using IE6 (or IE7):
1. when selecting some code, copy, paste, line breaks are gone
2. when selecting some code, copy, apply my tool, paste, line breaks are OK
but indents are gone
3. when selecting some code up to the closing PRE tag, copy, apply my tool,
paste, everything is fine
As such it is worse than most posts, since they do 2 and 3 fine.
All other browsers we have tested (Netscape, FireFox, Safari, Maxthon) show
no problem whatsoever in this regard.
I am still puzzled what the essential difference is between a small minority
of posts (including yours) and all the others. So I was hoping these few all did
the same unknown something while publishing. So far I dont know. Seems not.
Since each CodeProject page is a lot of HTML, it is really hard to tackle.
You will be able to read more on this next week, when the article will be published.
Regards.
|
|
|
|
|
Hi all
My combobox is html control I fill it from html control but I like to Conective his Items With my code from javascript What I can do
if you hava asmples give me it please
thanks evry body help me
Thaer
|
|
|
|
|
If your control has an id, you can use document.getElementFromId to get the control in javascript. What do you want to do with it ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi guys
any advise migrating C to C#? is there anything i should aware of?
thanks
|
|
|
|
|
Assuming you really mean C as opposed to C++, here is some basic info:
You will notice C# is object-oriented. Get used to it !
Try to grasp the benefits of "properties", they are great.
Dont try to solve all problems with "global variables" and lots of public members. Instead use classes, hide what does not have to be disclosed,
make all members either private or protected, and use protected or public
properties when your first reaction would be to use public members.
Normally you dont use pointers (they exist, but are used for solving
performance issues only, as in image processing; not for general usage,
such as say linked lists).
Arrays are objects too.
Dont worry about releasing objects; "new" does what "malloc" did for you,
"free" is to some extent automatic.
If you create an instance from a class that offers a public Dispose() method,
then you better end the object's life as soon as you are done with it,
by calling said Dispose() method.
that should get you started.
|
|
|
|
|
It's basically a full rewrite, and the idioms that drive a C program won't work, because C is not OO and C# is fully OO ( no non-OO code allowed ). As Guffa said, make sure you understand OO first, or your code will be a disaster.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Hi All,
I have on my Dialog 3 buttons - each of them call same method "GeneralButton_Click(...)"
I need to know witch button was click in the method - but i can`t do it by checking the text on the button.
How can i do it in different way ?
|
|
|
|
|
You can check the tag of the button, or just the button itself, work out which button it was directly.
You have three buttons with the same text ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
The text are not the same -
But the text can change - so i cant know witch button according the text.
Can i attach to the button some integer or something like that ? if yes so how can i do it ?
|
|
|
|
|
Like I said, the Tag property
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You have references to all three buttons, and you have a reference to the clicked button in the sender argument sent to the event. Just compare the references.
---
single minded; short sighted; long gone;
|
|
|
|
|
Like Guffa said. You can also evaluate the ID of sender to determine the identifier associated with the button.
|
|
|
|
|
Here is some code to summarise what others have said.
<code>
private void generalbutton_click(object sender, EventArgs e)
{
Button button = (Button)sender;
MessageBox.Show(button.Name.ToString());
}
</code>
|
|
|
|
|
private void GeneralButton_Click(object sender, Eventargs e)
{
Button btn = sender as Button;
// Do whatever here.
}
Mark.
|
|
|
|