Does CAtlArray initialize element to zero or not?

drjackool 956 Reputation points
2023-08-04T06:58:27.9866667+00:00

Hi

Does CAtlArray initialize element to zero or I have to set them to zero after calling SetSize() method?

I using this array to hold pointers!

CAtlArray<somestruct*> m_aItem;

Thanks

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,756 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 48,156 Reputation points
    2023-08-04T08:17:00.4933333+00:00

    The CAtlArray class does not have a SetSize method. Use CAtlArray::SetCount. ATL does not guarantee 0 initialized members. For example, if a CAtlArray object contained class instances SetCount would allocate memory and then call the default constructor for the class,. An implementation detail is that the calloc function is used to allocate memory so that will initialize the allocated memory to 0. So a CAtlArray object containing pointers will get NULLs in the newly allocated members.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.