|
Oooh - nice. I'd wondered if there was a way to create the jump table as a C variable, but hadn't thought of initialising it in assembly code.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello Stuart and David,
Thank you for your replies. Both solutions given are practical I think. I intended to use the branch table inside a time ciritcal part of my ray-tracer (ray vs axis aligned bounding box intersection test). I am building a stream ray-tracer using the sse ALU processing four rays in parallel. But the number of rays to process is not always a multiple of four to process the last 1,2 or 3 rays I thought to use a branch table. But I think I will make a funciton one for each case and use a switch statement ouside of the filter functions making the code easier to read and the c++ compiler does emit the code I would like.
Thank you for your help!!
|
|
|
|
|
A lot of jumps, and certainly those through a jump table, introduce a hickup in the instruction flow, as they are not predictable at all; so I'd rather avoid them.
assuming lots of rays I would take a different approach: if not a multiple of four, calculate one of the rays multiple times, e.g. duplicate the last ray one to three times so the number always is a multiple of 4. That probably will be simpler and may be faster.
|
|
|
|
|
Yes conditional branches can be expensive causing pipeline stalls. But in my implementation using streams of rays there is only one hard to predict branch and that branch is only taken once per processed stream so it is not really that important. But a c++/assembly mix looks alittle bit messy. Thats why I removed the branch table from my inline assembly function to improve code readability at the expense of code size. Expanding the number of rays per stream to a multiple of four is for me not an option because rays are partitioned in place. Meaning that the filtered stream or output stream should be of the same length compared to the input stream.
Thanks
|
|
|
|
|
I forgot to mention one technique I often use in cases like this, where the expensive jump is taken only once (upon entry); I'll describe it in pseudo-code, it basically is a loop unroll by 4:
switch(count%4) {
case 0:
goto case1;
case 1:
goto case2;
case 2:
goto case3;
case 3:
count-=4;
if (count>0) goto case0;
}
You can do this in any language, with a switch or with labels and jumps (and if the language allows fall-through, you may skip most of the goto's). In assembly, you would still need labels.
|
|
|
|
|
Hello,
I placed a break in the function OnKeyDown() of a class derived from CRichEditCtrl. But when I press F5 and debug the code the code doesnt proceed further but when I remove the break in the fucntion the code goes ahead . Ith this I am not able debug the OnKeyDown.
What should be done ?
Pritha
|
|
|
|
|
prithaa wrote: But when I press F5 and debug the code the code doesnt proceed further
Any further than what?
A breakpoint is meant to stop the code - you then have the option of what to do to make the execution progress.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for your reply
But when I press F5 the code goes further that is the cursor moves ahead but the the action doesnt reflect in the execution like suppose after pressing a right arrow key I want the cursor to move further on the dialog then the cursor doesnt move on the dialog. whereas if I remove the break in the OnkeyDown then cursor moves in the dialog.
I hope the question is clear.
Pritha
|
|
|
|
|
Well, if I've understood you correctly, that's because the breakpoint keeps on breaking - every time you hit OnKeyDown
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello,
Thanks
What is the meaning of the breakpoint keeps breaking ?
Pritha
|
|
|
|
|
Every time you reach the OnKeyDown handler, it'll break at the breakpoint.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks
so I should not be using breaks in OnKeyDown() is it? .It is wrong to use it like that ?
Pritha
|
|
|
|
|
Well - what's the bug you're trying to find?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Like all console input (keyboard, mouse events, windows focus and caret management) it's better to debug with writing debug messages to some (console or file). We either practice use Beep 's.
|
|
|
|
|
OK... I see two scenarios you are describing:
1/ With breakpoint.
a) App is running.
b) Focus is in a window.
c) You press f5.
d) This is a key going down, so the CSomeControl::OnKeyDown handler is called.
e) You have a breakpoint there, so it, erm, breaks and goes into the debugger, allowing you to debug you OnKeyDown handler.
This is a good thing.
2/ With no breakpoint.
a) App is running.
b) Focus is in a window.
c) You press f5.
d) This is a key going down, so the CSomeControl::OnKeyDown handler is called.
e) You have no breakpoint there, so the application carries on happily.
This is a good thing.
This may be a language problem (don't apologise for that!), but I can maybe see a 3rd scenario:
1/ With breakpoint.
a) App is running.
b) Focus is in a window.
c) You press some key.
d) This is a key going down, so the CSomeControl::OnKeyDown handler is called.
e) You have a breakpoint there, so it, erm, breaks and goes into the debugger, allowing you to debug you OnKeyDown handler.
f) You press f5 to carry on with the program, and it no longer works
If #3 is true, then I bet you're forgetting to hold down the original key before continuing execution. You application may be thinking "so, when is he releasing that key!? It's been down for a long time...".
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Thank you
I think the scenario is very much possible but then debugging OnKeyDown is pretty much difficult or not possible.
Thanks
|
|
|
|
|
I want to call any class from unmanaged dll. How can i do?
class __declspec(dllexport) foo{
public:
foo();
~foo();
void sum(int a, int b);
};
[...].class Foo{
[...]
void sum(int a, int b);
}
|
|
|
|
|
|
but i want to call functions from class. dllimport calls only c style functions, it doesn't support c++ classes
|
|
|
|
|
I don't think you can do that.
You will need to convert the class into a COM component and then do a COM interop.
COM interop is what Microsoft recommends.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Not true. You can export/import a class.
articles here: DLLs are simple: Part 2[^] and here http://msdn.microsoft.com/en-us/library/a90k134d.aspx[^].
On top of that you can demonstrate this by creating a DLL with the Visual Studio wizard. Create a Win32 project and select export symbols.
I missed the C# part of your question. You are posting in the wrong forum. You also phrased your question incorrectly, which mislead me. You used the terms "unmanaged class" and "DLL" and then threw in "the C# side."
Incidentally, if you "own" the C++ side, you can add the CLR switch to its project and use C++/CLI. (Frankly, I usually find it easier to convert the class in question to C#, but I have done what I just described.)
|
|
|
|
|
You should use COM objects to access C++ classes like that from .NET.
Life is a stage and we are all actors!
|
|
|
|
|
I apologize for my previous answer. I misread the original question due to him mixing terms.
That said, I still disagree somewhat--if he "owns" both sides, he can simply create the C++ DLL using C++/CLI.
|
|
|
|
|
As seen by my other answers, the phrasing of your question annoys me. The subject is "calling unmanaged class from DLL" and then you say you want to call "any class from unmanaged DLL." What is it? Are you wanting to call .NET from native C++ or call native C++ classes from .NET?
In the former case, you can host .NET in your C++ application (which is a lousy idea, but you can do it.) In the latter case you can convert the native C++ to C++/CLI and call it that way. I personally find it easier to convert the C++ classes to C# (and occasionally use a native, helper DLL with procedural APIs.)
On top of that you give a code snippet that makes no sense. If you have a C++ foo and a C# Foo, what do you care?
|
|
|
|