Solved

Need help with CPtrArray

Posted on 1998-05-07
2
858 Views
Last Modified: 2012-06-27
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
Comment
Question by:jrmcg
2 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 1174310
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
 
LVL 2

Author Comment

by:jrmcg
ID: 1174311
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question