CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 5 1234 ... LastLast
Results 1 to 15 of 65
  1. #1
    Join Date
    Sep 2006
    Location
    Moscow, Russia
    Posts
    67

    CArray vs. std::vector

    What faster?
    And what containers is better to use in general MFC or STL?

    P.S. I`m using MSVC.

  2. #2
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582

    Re: CArray vs. std::vector

    std::vector. No comparison.

    Jeff

  3. #3
    Join Date
    Sep 2006
    Location
    Moscow, Russia
    Posts
    67

    Re: CArray vs. std::vector

    Quote Originally Posted by ncode
    What faster?
    And what containers is better to use in general MFC or STL?
    ... And what about CString and std::string?

    I `m going to rewrite some parts of my project to STL.

  4. #4
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582

    Re: CArray vs. std::vector

    Quote Originally Posted by ncode
    ... And what about CString and std::string?

    I `m going to rewrite some parts of my project to STL.
    Well, here you might get some debate. std::string does not supply the complex interface that CString does.

    However, once you use a library like boost::string_algo, you'll be much better off with std::string.

    My recommendation: use boost + std::string. It's more portable and powerful.

    Jeff

  5. #5
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: CArray vs. std::vector

    In my experience STL is much much better than MFC.
    My hobby projects:
    www.rclsoftware.org.uk

  6. #6
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CArray vs. std::vector

    Quote Originally Posted by ncode
    What faster?
    And what containers is better to use in general MFC or STL?

    P.S. I`m using MSVC.
    IMO STL vector is superior.

    Also, the MFC CArray container has a serious bug when copying data (cilu would know more about this, since I believe he discovered the problem).

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: CArray vs. std::vector

    Quote Originally Posted by ncode
    ... And what about CString and std::string?

    I `m going to rewrite some parts of my project to STL.
    Well, as jfaust says, CString vs. std::string is debatable, but only if you plan to use the new version of CString that is templated and decoupled from the rest of MFC (CStringT is the templated class, and from what I remember, you can use it standalone from the other MFC classes).

    If you are using Visual C++ 6.0, then attempting to use CString and only CString without introducing other parts of MFC -- well it is very error-prone and not worth it. In the case of Visual C++ 6, use std::string.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: CArray vs. std::vector

    Prior to considering the right choice based on efficiency and issues, comes the concern of portability.

    If you are writing portable applications - you should try sticking to standard solutions otherwise you would consider other platform specific solutions.

    Moreover, if it is an MFC application i.e. a framework based you should be better using framework based solutions (standard solutions are also a good choice but as long as they are not exposed to the public interface - they should be hidden as an implementation detail). Otherwise, you will almost see yourself overloading things for two types - CString and std::string or CArray and std::vector. You would also see yourself converting the types at all places where any cross interaction happens. These are un-necessary and can be avoided. If it is not especially an MFC application - you should be well off choosing a standard sequence.

    Also, note that if you are working with wide-character type, you would use wstring.

  9. #9
    Join Date
    Aug 2000
    Location
    New Jersey
    Posts
    968

    Re: CArray vs. std::vector

    In general, the STL is far better then MFC counter part.

    However, CString not only provides better functions, but it's also more efficient then the std::string that comes with VC++ 6.0.
    If portability is not an issue, I would recommend CString over std::string.
    IMHO, there's nothing wroing with mixing STL and MFC, like std::vector<CString>

    Also consider that it can be easier to port a ANSI MFC appliation using CString to a UNICODE application, then it would be if you were using std::string + std::wstring
    David Maisonave
    Author of Policy Based Synchronized Smart Pointer
    http://axter.com/smartptr


    Top ten member of C++ Expert Exchange.
    C++ Topic Area

  10. #10
    Join Date
    May 2010
    Posts
    54

    Re: CArray vs. std::vector

    Hello, in my assignment, I also use vector<CString> should this be better than CArrayString performancewise?

  11. #11
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: CArray vs. std::vector

    Quote Originally Posted by emailus View Post
    Hello, in my assignment, I also use vector<CString> should this be better than CArrayString performancewise?
    wine + vodka = headache

    Once you are using the MFC class CString, then use the MFC CStringArray class as well.
    This may increase a little bit the performance but it's not so important.
    Important is the resulting more headache-free code.

    Ask your teacher if I'm right...
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  12. #12
    Join Date
    Dec 2009
    Posts
    145

    Re: CArray vs. std::vector

    Yes of course, CArrayString performs worse than vector<CString>
    But look, the vector has to construct their ctors at least twice
    Carraystring is available/builtin class in the framework. Carraystring is composed also of many useful functions to easy-access and use. MFC is old but widely used framework at the present, rewriting the library to optimize everything would be what all developers are afraid of. The STL is newer and updated more frequently. It doesn't create much difference for moderate-mid sized application.

  13. #13
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: CArray vs. std::vector

    Quote Originally Posted by jfaust View Post
    std::vector. No comparison.
    There were TWO questions in the original post; which one are you answering?
    “No comparison” in performance? Or ease-of-use?
    In any case, some justification might be useful.
    It would also help to compare specific versions of MFC and STL.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  14. #14
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: CArray vs. std::vector

    Quote Originally Posted by Ledidas View Post
    Yes of course, CArrayString performs worse than vector<CString>
    Is that a fact or your opinion? Based on what?
    Without benchmark, this argument sounds just silly. Particularly the “of course” part.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  15. #15
    Join Date
    May 2009
    Posts
    2,413

    Re: CArray vs. std::vector

    Quote Originally Posted by ncode View Post
    What faster?
    And what containers is better to use in general MFC or STL?

    P.S. I`m using MSVC.
    I would go for STL any time.

    Even when you use MFC and is married to Windows it's better to use standard C++ as much as possible. Why? Becuse you minimize your dependency on a specific company that's why. Even if you're not planning to divorce MS it may suddenly decide to divorce you.

Page 1 of 5 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured