[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 893
  • Last Modified:

Need help with CPtrArray

I have written a socket server and client application that manages 22
different sockets at any given time.  Each socket is using the same server
address but has a different channel.  Two sockets have their own dedicated
pointers and then there are 20 data sockets that I open on the heap with the
same pointer name.  To keep track of those 20 data pointers I am trying to use
a CPtrArray to hold them.  I don't get any compile or run-time errors, but the array
is not being loaded with the socket pointers.

CPtrArray pDataSockArray;
pDataSockArray.SetSize(MAX_DATA_CLIENTS,-1);

CDataSocket* pDataClient;
pDataClient = new CDataSocket;
pDataSockArray.SetAt(0, pDataClient);

This does not work.  I looked at the example in ChatSrvr
on MSDN and it uses a CPtrList.  I need to be able to access
the pointers by index not sequentially.  What am I doing wrong?
Is there a better way?

Help    -- jr
0
jrmcg
Asked:
jrmcg
1 Solution
 
RONSLOWCommented:
What do you mean by "not being loaded with the socket pointers"?

Have you set a break point to ensure that the SetAt is happening?

And shouldn't that be SetAtGrow (so you don't overflow the array).

Also, you are better off using the CArray template class as that way you don't loose type info by the casting to void* that CPtrArray does.


0
 
jrmcgAuthor Commented:
Thanks - I corrected the SetAt call, I found that it was working correctly
but I had the call in the wrong place.  I am going to look into the CArray
template class.  That does seem to be a better option.

-- jr
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now