0

In my program iam used CArray for storing some values. But the performance is low when using CArray member functions. such as iterating the CArray. iam used member function like Copy, GetAt, Append, etc. because of low performance iam decided to use CMap class instead of CArray. Is my decision is correct? anyone explain it?

1
  • At this moment you should not be using MFC containers, but STL containers ... unless you are giving maintenance to an old code base or you have another strong reason to use the former.
    – sergiol
    Jun 24, 2016 at 16:47

1 Answer 1

2

Have a look at this: Recommendations for Choosing a Collection Class

We must select the collection class not only based on performance. It depends on the kind of data structure you want, operations you want to perform on it etc.

Since you said you want to "store some values" I assume no further complexity. For that, you can use either a CArray or CList. Lists are faster when inserting a value, but it is not indexed. i.e you cannot access the elements at a particular index, you need to traverse the list instead.

CMap is faster than both CArray and CList, but it is better to use it if you have a collection of complex data structure where a unique key is available to index each element.

1
  • At the moment, I would not recommend to use any MFC collections for new code. Presently they have absolutely no advantage over std library collections. May be @IInspectable disagrees with me.
    – sergiol
    Apr 29, 2021 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.