Solved

Need help with CPtrArray

Posted on 1998-05-07
2
833 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now