Solved

Need help with CPtrArray

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

914 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

14 Experts available now in Live!

Get 1:1 Help Now