Hi.

I am stuck at on design that include extensive use of pointer. I prefer using point because with pointers, I have more options such as when to create the data structure and when to delele the data structure. Furthermore, I have more options when passing the pointers to functions. Nonetheless, pointers can be tricky when dealing with some API and other Windows based tools such as MFC.

Here is the problem. In Winsock programming, there are API functions that does "clean up," according to Anthony Jones and Jim Ohlund, authors of Network Programming for Microsoft Windows, Second Edition. Some of these API functions include these functions:

// closesocket(...) // you pass in a sock
// freeaddrinfo(...) // you pass a pointer to a struct addinfo
// WSACleanUp() // you pass in nothing

Okay. Those are just a few "clean up" functions for Winsock. I am sure there are some other ones. Here is my question.

As I have mentioned that I prefer using pointer and creating a new data structure and deleting the pointer when needed. That technique gives me more flexibility. However, with respect the the "clean up" functions above, how do they react to pointers? For example:

// sock *mySocket = socket(...); // mySocket is a pointer to a socket

Now I close it.

// closesocket(*mysocket);

Now, should I still call delete mySocket afterward? My main concern is I do not know whether each the API function mentioned above the pointer if you pass it a pointer.

The same scenarios holds for freeinddrinfo and WSACleanup().

In the case of a struct inaddrinfo, you pass in a pointer. However, do you delete that pointer afterard?

In the case of WSAData, do you delete the pointer to a WSAData structure after calling WSACleanup()?

Currently, I *do* delete all pointers even after calling WSACleanup().

Thanks,
Kuphryn