Share via

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 development | Windows API - Win32
0 comments No comments

Answer accepted by question author

RLWA32 52,571 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.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

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