|
Hi All,
I am working on UDP sever module.I have developed a simple server for receiving and sending the data from a single client.
in "OnReceive()" handler only I am sending the data to the client using "SendTo()" function,
How can I extend this to multiclients.
Please give me an idea.
Plese provide me if anybody has the sample code.
Regards,
Sunil Kumar
|
|
|
|
|
Did I really needed multiple threads to handle UDP clients? Wait..scanning old dumps in brain.....oops, bad sectors. Search ends.
You are unlucky. let;s wait for someone to answer you.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hi to all,
I am have written some classes in C++ as follows,
Class A
{
int b1Len; //count of B type objects in b1Collection
B *b1Collection; //stores collection of object of type B
int b2Len; //count of B type objects in b2Collection
B *b2Collection; //stores collection of object of type B
};
Class B
{
int cLen; //count of C type objects in cCollection //cLen is atleast 30
C *cCollection; //stores collection of object of type C
};
Class C
{
int d1Len; //count of D type objects in d1Collection //d1Len is atleast 140
D *d1Collection; //stores collection of object of type D
int d2Len; //count of D type objects in d2Collection
D *d2Collection; //stores collection of object of type D
int e1Len; //count of E type objects in e1Collection
E *e1Collection; //stores collection of object of type E
int e2Len; //count of E type objects in e2Collection
E *e2Collection; //stores collection of object of type E
};
Class D
{
int fLen; //count of F type objects in fCollection //fLen is atleast 2
F *fCollection; //stores collection of object of type F
};
Class F
{
int len; //count of characters in str //len is atleast 200
char *str; //stores multiple characters
};
int aLen; //count of A type objects in aCollection
A *aCollection; //stores collection of object of type A
DelAll(aCollection, aLen); //aLen is atleast 30
//it's a macro to delete array of objects of any type
#define DelAll(obj, no) if( obj != NULL ) { if( 0 < no ) { delete[] obj; obj = NULL; } }
I am using this macro in destructor of all class (above) to delete array of objects.
My problem is, it's takes atleast 0.86 secs
Is there anything wrong I am doing?
I am using VC++ 2008 as IDE.
Thanks & Regards,
Aniket A. Salunkhe
|
|
|
|
|
It'd be helpful if you post a working code. The above class structure and objects wont take too much time.
Please carefully check the destructors of the classes. You can roughly calculate the time using OutputDebugString API. Just start Debug View Tool and set the time to display in Milliseconds. then execute the code after putting enough log. or use some profiling or logging mechanisms to get the critical point.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi to all,
Thanks for your suggestions.
In every class I was using Add___() function to add object of other class.
I was reading a 35 MB xml & using that I was calling Add___() every time a found an object of class A, B, C, D, .. & I was getting problem at DelAll macro (it was taking more time to execute that might be due to lot of data).
Now I have replaced the Add___() function call, by it’s function body. Now it is taking normal time to execute DelAll macro
<br />
class A<br />
{<br />
void Add_B(const B* newBs, int newBsCount)<br />
{<br />
if( newBsCount <= 0 )<br />
return;<br />
<br />
B* temp_Bs = NULL;<br />
<br />
if( 0 < AllBsCount )<br />
temp_Bs = new B[AllBsCount ];<br />
<br />
int i<br />
for( i= 0 ; i < AllBsCount; i++ )<br />
temp_ Bs [i] = AllDays[i];<br />
<br />
DelAll(AllBs, AllBsCount)
<br />
AllBs = new B[AllBsCount + newBsCount];<br />
for( i = 0 ; i < AllBsCount; i++ )<br />
AllBs [i] = temp_Days[i];<br />
for( i = 0 ; i < newBsCount; i++ )<br />
AllBs [AllBsCount +i] = newBs [i]; <br />
<br />
DelAll(temp_ Bs, AllBsCount);<br />
<br />
AllBsCount += newBsCount;<br />
}<br />
}<br />
Thanks & Best Regards,
Aniket A. Salunkhe
|
|
|
|
|
(not really an answer)
Why are you using C type "collections" instead of std::vector (or std::list) ?
Are you checking the time in DEBUG or in RELEASE ?
I don't see much wrong in what you presented if the destructors are really deleting what has been allocated;
you probably have more data than you are expecting.
|
|
|
|
|
It looks like you have many arrays of objects, and a destructor is called for EACH array element. It may be possible to delete the whole array with one statement, if your destructor is just freeing memory (as opposed to executing cleanup code).
For example:
D* dArray = (D *) malloc (numberOfDObjects * sizeof (D));
...
delete [] (char *) dArray;
This invokes delete once, rather than numberOfDObjects times. You may be able to use similar logic for arrays of arrays of objects.
|
|
|
|
|
malloc and delete do not play well together.
did you meant to use free instead of delete ?
|
|
|
|
|
Oops, my mistrake. You can use free ((char *) dArray), or
D* dArray = (D *) new char [numberOfDObjects * sizeof (D)]; and
delete [] (char *) dArray
|
|
|
|
|
Is it surrounded by a bunch of try ... catch blocks? it shouldn't take is much time though. Even in debug mode.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
How to insert struct data using SafeArrayPutElement() method?
|
|
|
|
|
This thread[^] seems useful to you.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
What type (e.g., VT_x ) of VARIANT object to you have?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
|
How to get the size of memory pointed by void * pointer?
Thanks in advance!
|
|
|
|
|
Generally there is no way that will work on all conditions. How ever if you are sure that, the pointer will be pointing to a memory allocated using new operator, you can use the _msize function.
|
|
|
|
|
You could use _msize()[^]. For instance,
#include "malloc.h"
...
void* pPointer = new BYTE[100];
int size = _msize( Ptr );
Please note that it won't work if the memory is allocated in stack. Only for memory allocated on heap. Hope it helps.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thank You.
Now how do I write any structure to a xml node?
Any idea?
Thanks in advance!
|
|
|
|
|
Ah! Now i got the context about what you're trying to do. Export the BITMAP to XML? Bravo! i'd say.
IMHO, Instead of dumping the BITMAP structure to XML, just get the bitmap data by calling GetBitmapBits()[^] and other necessary information such as width, height, color depth and save that to XML file. Later on by loading these values, you can recreate the bitmap by calling the function - CreateBitmap()[^]. Hope this helps you.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
yo buddy.. that will surely help. Thanks!
|
|
|
|
|
I have a BITMAP structure. I need to write it to a xml file.
How do I do this?
|
|
|
|
|
However the hell you want!!?!
Define the structure you'll use to store the info, then fill it - simple.
If you need a prod-along, why not just make the XML file hold ( a subset of) the same info as the BMP file would, in the same order.
E.g for a 5x5 pixel red square, I may use something like:
<BitmapFile>
<FileInfo>
<Width>5</Width>
<Height>5</Height>
<BitPlanes>1</BitPlanes>
<BitsPixel>24</BitPixel>
<CompressionType>0</CompressionType>
<xPixelsMeter>2835</xPixelsMeter>
<yPixelsMeter>2835</yPixelsMeter>
<ColsUsed>0</ColsUsed>
<ColsImportant>0</ColsImportant>
</FileInfo>
<ColorData>
<ScanLine> FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 </ScanLine>
<ScanLine> FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 </ScanLine>
<ScanLine> FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 </ScanLine>
<ScanLine> FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 </ScanLine>
<ScanLine> FF 00 00 FF 00 00 FF 00 00 FF 00 00 FF 00 00 </ScanLine>
</ColorData>
<BitmapFile>
One of the many problems with his approach is, that I can't remember if compressed pixels runs are allowed to cross scanLine boundaries (one compressed stream may not end at the end of the scanline it was begun in)
Please excuse me if it's a little forward, but why don't you use ZLib? Instead of busting up all the files for transfer and storing the info into a single large XML file, you could just compress the files together into an archive, and send that. This should provide you with smaller transfers & faster execution since the files are all binary rather than textual representations of the same binary data.
|
|
|
|