|
In our current environment performance is pretty important so we compile our C++ code with exceptions turned off and the coding convention is totally avoiding the use of exceptions. Some say that compiling the code with exception handling can be -5 to -10% in performance depending on the compiler because of the boilerplate code generated. I think -5 to -10% is not so big waste in programs where performance is not extremely critical and in return you get a much cleaner code with exception handling because you don't have to return with some kind of error indicator value and you don't have to check this value after every function call. Unfortunately the use of exceptions in C++ is indeed not as pretty as in some other languages like C# and Java, it has some pitfalls so you have to make your choice whether to use them or not. I found a really nice discussion about this: C++ Exceptions: Pros and Cons[^]
|
|
|
|
|
It's true that stack based exception handling has an overhead even when exceptions are not raised (this isn't true for table based exceptions). That said I was referring to the cost when they are raised too frequently, in particular for non-exceptional cases such as returning values.
Steve
|
|
|
|
|
I suspect most if not all c++ compilers use the table based version, but unfortunately it still has an overhead. Not big, but more than zero. For most C++ programs that is not an issue.
|
|
|
|
|
I was partly wrong in my previous post because I misunderstood "table driven". There is an x86 and an x64 version of the table driven exception handling, the x64 version is working like you said. What I meant is the x86 version that was SEH + tables. We are still on x86.
|
|
|
|
|
Hi all,
For my current project[^] I need to use a function pointer to allow a QueueHandler to execute the task of a QueueObject.
I know about what a function pointer is, no worries I searched the net[^] a bit.
I got one question:
-- Is there a possibility to point towards a function without knowing what it exactly returns, and more important without any knowledge of the count and type of the parameters?
In the end it should be like the delegate I know from the .NET side of multithreading.
Thanks for all suggestions in advance.
[Edit: To the univoter who stroke down this question:
Either explain why you have down-voted or go and die in a f*cking fire you moronic ********]
modified 21-Mar-13 11:55am.
|
|
|
|
|
I don't think you can do this in C/C++. How would you pass the correct parameters if you don't know the type and count, and how would you handle whatever it returns? I guess the only possible way round it would be to send a void* to some memory area containing the required parameters, or use the void func(...) type definition. But you still need to know the input and output types in the code that calls the function.
Use the best guess
|
|
|
|
|
Thank you for your reply.
Another idea which came to my mind: Can I use a array of pointers of an unknown type as arguments for the function?
In this case I'd be able to force the user of the tool to just give this array as a parameter.
This approach would look like
int (*DoTaks)(void[]);
Please correct me if I am wrong.
|
|
|
|
|
Marco Bertschi wrote: Can I use a array of pointers of an unknown type as arguments for the function?
I would say, yes, you can do that, but it's dangerous because it's not type-safe. This type of code would be filled with casts and could be very difficult to get right.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank you for your answer, I understand the problem.
Is there any other way to get something like a delegate in native C++?
|
|
|
|
|
Even for a managed delegate you need to define the paramter types and return type. I would suggest defining a class or struct containing all the parameters you need to pass and additionally a kind of type that tells the receiving function which members it needs to use. Then you pass just that struct as parameter.
|
|
|
|
|
Freak30 wrote: I would suggest defining a class or struct containing all the parameters you need to pass
There does the problem start. I don't know which parameters are needed because I do not define the method which is executed. It is needed as a part of this project[^] (as I have mentioned in the OP).
Thank you for your help anyways.
|
|
|
|
|
After viewing your link, i couldn't help but wonder if a deque would be better. (aka work stealing - google Cilk)
All tasks take work from the front of its own queue, but an idle task takes work (steals) from another by removing items from the back of its queue.
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
That's what machines are for.
Got a problem?
Sleep on it.
|
|
|
|
|
Yes you could do that (you need int (*DoTaks)(void*); notation), but you still have the problem that any mistakes with the parameters cannot be spotted by the compiler. If you are happy to live with that risk then go ahead; a small prototype should help to clarify the issues you may face. Something like:
struct aStruct
{
int value;
char someText[12];
};
int func1(int pvParameters[3])
{
return 1;
}
int func2(aStruct* paStruct)
{
return 2;
}
void DoTest()
{
int myArray[] = { 1, 2, 3 };
aStruct myStruct = { 5, "data" };
int (*DoFunc)(void*);
DoFunc = (int (*)(void*))func1;
int r = DoFunc((void*)myArray);
DoFunc = (int (*)(void*))func2;
int r2 = DoFunc((void*)&myStruct);
}
Use the best guess
|
|
|
|
|
i would like to ask a question regarding to the subject above ,the question is like this "There is an array of String type named arrFruits with the following values: pear, banana,
apple, cherry, watermelon, papaya. Sort the contents using an appropriate sort routine and
display the sorted data from the same array."
& "Randomly enters 10 alphabets into arr_A. Then allow the user to enter a value into a
variable. The value of the variable is then compared with the values in arr_A. If there is a
match, the program will display the subscript of the cell containing the target value. If
more than one of the cells contains the target value, then the function should return all the
subscripts that has the identical values with the variable." if someone could help me solve my problem i would very appreciate your help thank you. // please add remark to the code thank you
|
|
|
|
|
Sorry, but no one is going to do your homework for you. Try writing your array items out on a pice of paper and think how you would sort them in order, how you would find one beginning with a specific letter etc.
Use the best guess
|
|
|
|
|
I try to do some of the code for this question but didn't success, can u help me solve it? here is the question together with the answer I done.
Task 3 (Question)
Using two arrays, named arr_A and arr_B respectively, write a function named
concantenate that join the values from arr_A to the values from arr_B according to their
sequence and stores the concatenated values in arr_C. Display the contents of arr_A,
arr_B and arr_C. The three arrays are declared as integer type
My Answer
#include <iostream>
using namespace std;
void concantenate(int arr_A, int arr_B, int total)
{
int arr_C;
for (int n=0; n
|
|
|
|
|
I think you should go back to your notes and re-read the section on variables and arrays. You could also read some of the MSDN documentation[^].
Use the best guess
|
|
|
|
|
Please read the "How to ask a question"-Guide. We do not solve homework, neither do we give away code when we are asked to.
|
|
|
|
|
Hello All,
I am usnng SOCK_DGRAM and getting error 10035 in recvfrom(). Any help....
|
|
|
|
|
See WSAEWOULDBLOCK at Windows Socket Error Codes[^].
To avoid this use event driven receiving. That is, call recvfrom() only when an event indicates that data are available or use overlapped IO.
|
|
|
|
|
thanks but how to fux it?
|
|
|
|
|
There is no simple fix. This error must be handled by your code in some way. In fact it is not an error, but a status information: There are actually no data in the receive buffer.
A simple solution would be to wait a short time when this error occurs and then call recvfrom() again. But this is a bad design.
You must design your receive code to handle such situations (waiting for data coming in). With Windows, this is usually done using overlapped IO and a worker thread. Examples can be found in many Winsock tutorials and here at CodeProject.
|
|
|
|
|
I do apologize to all who helped me in past with my attempts to replace VFW with DirectShow.
This may be too repetitious, sorry.
I got as far as implementing COM and displaying AVI file, but I just cannot get the DirectShow to display video. My “problem” is that DirectShow “SDK” appears to be DIFFERENT with each new MS IDE release. At one point (DirectShow SDK 8.1) it looks as I need to build a base DirectShow library from scratch. But I have not tried that , not yet.
I feel as MS does not understand the basic concept of C language extensibility, at least it looks that way when it comes to DirectShow.
I took a peak on Gstreamer, but it seems dead and without decent support for Windows.
So the main question for now – are there another true = independent of IDE , “C” video libraries out there?
I'll admit I have not looked at CxImage lately, but it was pretty dead years ago.
Thanks for your continuing support.
Cheers
Vaclav
|
|
|
|
|
I am sorry to hear that, but I don't mind even though I tried to give you a few pointers earlier.
Where are you at now with the Visual Studio version?
I am not having any problems with my DirectShow projects on VS2010 even though I cannot seem to convince it to use the paths for v7.1 of the Windows SDK instead of the v7.0A paths.
Anyway, if you have gotten to the point where you just don't want to try to deal with DirectShow, one way is to go with OpenCV[^]. People often write about OpenCV's features for image processing, video analysis and stuff like that, but it also has video capture and display functionalities. I have not actually used it for that myself, but there are several articles here on CP, such as these:
- An Introduction to OpenCV: Displaying and Manipulating Video and Motion Data[^]
- An introduction to OpenCV (Part II): Implementing mouse events, manipulating images, and creating video clips[^]
Best of luck.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Soren,
I am using OpenCV for the actual video frame processing.
The “problem” with OpenCV – it is build on VFW (!) which everybody here discouraged me to use since it is “obsolete”. OpenCV does not use VFW callbacks, as intended, but the image is captured in plain loop which in my opinion defeats the event driven system philosophy big time.
I am still using VC++ because my base application is build on MFC and in VS MFC is either nonexistent or cost $.
I am happy with VC++ MFC. The main reason I started to look for something else to do the video capture is I use VFW directly - single frame capture and it is very unreliable and I get blank screen MOST of the time.
I have not found anybody knowledgeable enough to resolve this reliability problem. I did try to fix it using “number of bytes used” ( I may not be using correct term here) and it is never the same so I cannot tell when the frame “bitmap” is actually empty.
I have not tried “streaming image” instead of capturing single frame.
Just for kicks I may try that approach next.
Thanks for your support.
Cheers
Vaclav
|
|
|
|