November 18th, 2010, 11:45 PM
Winsock using IOCP / Memory Freeing
Okay well I've actually got a few questions and was hoping a more experienced programmer could help me out. I expect I'll probably getting a response saying their is a better language for doing this but I enjoy the challenge.
Okay so here goes, my setup is basically I'm creating a complex chat server in C++ that interfaces with a Java client that is applet based. The setup is a main server interface thread that spawns a server listener thread and (3*processors) worker threads. It uses overlapped sockets and a completion port to detect when users have data coming in. My first attempt at this was the 1 thread per client model which will cause issues considering I expect to have > 1000 threads at once.(context switching and what not). This model seems to be the best of all models but is very hard to find documentation on but as of right now I have a basic chat server and clients running.
Keep in mind that not all users will be interacting with each other, there will be several chat sites under the server that will then be separated into rooms. So here comes my issue, and I've tested it myself. I logged into the chat with about 60-70 users and it is stable but when a user sends a message the process has to iterate through the user list for that particular site and this is time consuming, >500ms to get to the last user. This is using the local loopback so I realize this could be an issue but what I'm hoping for is a way to issue 1 send command that could send a message to a socket list of some sort instead of issuing a send command for every individual user.
Okay one more question and it will sound very dumb but I've looked everywhere on the net and I can't figure out an exact example spelled out in black and white. When do I exactly need to free memory? I know I need to issue a delete for every time I use new but what about variables that are just created in a function, pointers, character arrays....? Also, when creating a destructor for a class what type of free should be made on what particular types of variables? I use vectors a lot because they are convenient, do I need to free every time I use one?
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!