|
CSocket does not create a separate thread. It does however create a window which is used as an event sink for asynchronous operations. When an asynchronous operation such as Send is invoked the CSocket object will enter the message pump until the operation is completed. Once the operation completes the event is placed in a queue and then dispatched to the appropriate method (OnSend, OnAccept, etc).
Overall CSocket is more suited for general client connectivity rather than servers - especially high load servers. You would be better off calling the Winsock API directly and using IO completion ports.
1300 calories of pure beef goodness can't be wrong!
|
|
|
|
|
Bacon Ultimate Cheeseburger wrote: CSocket does not create a separate thread.
Are you sure? I was pretty sure it did.
OK, I just ran the debugger on one of my programs that uses a CAsyncSocket object. The debugger shows a thread named _SockAsyncThread@4 in the list of threads. Since CSocket is derived from CAsyncSocket, I assumed it would also create a thread.
|
|
|
|
|
wmallory wrote: Are you sure? I was pretty sure it did.
SockAsyncThread is a thread entry point used by service providers for handling asynchronous socket operations.
I am a lean mean ground beef machine!!!
|
|
|
|
|
Ah... that's quite a bit different than what I was assuming. Thanks for the info.
|
|
|
|
|
includeh10 wrote: From CSocket idea, I do think thread is not neccessary, however, I have a little suspection about this.
CSocket is a wrapper around an event based networking model. If you want to get better performance have a look at CAsyncSocket or IO completition ports. Further information in the Winsock programmer's FAQ[^]. Hope it helps.
/M
|
|
|
|
|
Hi all,
I'm in the process of writing my own Matrix Library, and have been using the standard way to copy things around, i.e. if i have a pointer to a bunch of doubles, say
T * my_doubles = new T[64];
representing an 8 by 8 array, then if i want a copy constructor of a class to duplicate this then i just issue the following code in the copy constructor:
for(unsigned int count = 0; count < 64; count++)
new_doubles[count] = my_doubles[count];
however, i have been reading around on the net that there are faster ways to copy memory, mainly using memcpy. i have also learned that some people are against the use of this because the compiler optimizes code such as that above to be the most efficient.
so what's it to be?... regarding SPEED, is it really best to let the compiler optimize, or use memcpy, or some other method?... and if so what are these methods?
Many thanks,
Paul
|
|
|
|
|
Why don't you do some tests?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hmm... Fastest way to copy memory.
I was thinking of a memory copying API tied to a Hayabusa.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Indeed: My pen drive is quite fast memory when I drive the GSR..
BTW: nice THHB action, today...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
So, you mean to say that we cannot talk among ourselves? Did you not see the joke icon even? Why the "unhelpful" vote?
Take it easy, those replies were not given to you.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: Why the "unhelpful" vote?
It doesn't come from him. It comes from his friend...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hey, i didn't write your replies for you. chill.
however, i did do some tests, and memcpy is way faster - in fact, wherease memcpy comes in at 0 clocks (for some small copy routine), both the pointer copy and index copies both come it at around 1300 cycles.
WOW !
|
|
|
|
|
I actually suggested you to perform some tests. What's better than experimental evidence?
As a guess, I suppose that a library function maybe faster than your (even optimized) code. I would try a Win32 API function like CopyMemory (if code portability is not a concern) [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thanks - the memcpy function seems lightning fast. for a small copy routine, memcpy came in at 0 cycles whereas index and pointer copies came in around 1300 cycles for the same test..
i'm sticking with memcpy ! !
cheers,
|
|
|
|
|
Rajesh R Subramanian wrote: tied to a Hayabusa
Is this how your little monkeys get their answers so fast?
Best Wishes,
-David Delaune
|
|
|
|
|
Usually, the steroid injected, genetically altered bananas do the magic. But yes, sometimes they need a superbike.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I did test about this before:
pointer increasing is faster than index increasing.
i.g.
WORD*p0=...;
WORD*p1=...;
this code is faster:
for(i=0;i<1000;i++)
{
*p0=*p1;
p0++;
p1++;
}
than:
for(i=0;i<1000;i++)
{
p0[i]=p1[i];
}
|
|
|
|
|
thanks, i'll try something similar to this. cheers for helpful comments.
|
|
|
|
|
such timing experiments are tricky. Here are some things to consider:
- compiler settings, including debug vs release
- timer inaccuracies; make sure to have a timer with good accuracy
- cache effects; when testing several alternatives, the first will often loose because the data hasn't been cached yet.
etc.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
memcpy is generally fastest. I've found several places where VS2008 (at least) optimized a loop like above into a memcpy.
|
|
|
|
|
I chose a few memory copying functions and did a profiling, and I see memcpy is the fastest (VS 2008). I haven't gone to the extent to see what the compiler has optimized it out into; I only did profiling, several times. memcpy was slightly faster on an average.
Also, a modern compiler must be able to optimize your code out to something that's fastest, unless of course you write some deliberate bad code.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Many compilers (including MS C++) support intrinsic function calls which are inlined during the compile phase. This includes calls to memcpy, memcmp, memset, strcpy, acos, asin and more. If you have not already enabled intrinsic functions you might wanna give it a try.
For more information on intrinsic functions click --> here <--
1300 calories of pure beef goodness can't be wrong!
|
|
|
|
|
I knew of intrinsic functions, but I hadn't known that memcpy was amongst the list of functions that the MS C++ compiler has intrinsic versions of.
Thanks.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
memcpy will be faster, in general.
and if you want to get crazy, an SSE/MMX version of memcpy can be even faster.
|
|
|
|