Thread: Rewrote my cMap class. Looking for more criticism

  1. #16
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Raigne View Post
    I doubt that the underscore thing will matter if it is a member.
    I doubt you'd run into a problem either, but then again, it's also possible that the compiler's header files could use macros with underscores, which would mess up names whether they're part of a class or in a separate namespace...
    I remember having to #undef the min & max macros when I include the <windows.h> header and I also want to use the std::min() or std::max() functions; and that's not even using any underscores!
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by cpjust
    Actually only names that begin with two underscores, or a single underscore and either a capital or small letter (I can never remember which it is) are reserved for the compiler.
    More accurately, names that contain two consecutive underscores, or begin with an underscore followed by an uppercase letter, are reserved to the implementation for any use. Names that begin with an underscore are reserved to the implementation for use as a name in the global namespace.

    Consequently, the name _Copy is reserved even with respect to class members, but a user is free to use the name _copy for a class member.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Additionally, why create a function name beginning with an underscore to begin with? It just looks weird...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #19
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    If you want to know how much memory it uses, then the answer is some constant multiplied by the maps size(). You don't need to track anything yourself. So you may as well rip out all the unnecessary stuff you've got to try and track memory usage. The constant I mention should be about 3 times the size of a pointer plus the size of your item type (if stored by value).

    Storing objects in a map by pointer does not increase speed regardless of what crap someone has fed you. If you stopped doing that then you could eliminate your _Copy function and your copy-constructor and assignment operators.

    The whole m_cList is totally unnecessary. If you want to store items in a map by an integer cookie, then you can probably get away with each new cookie being equal to the highest cookie currently in use plus one. Or another tecnhique is to have a loop that generate a random int, tests if that index is in use and exits when it finds that index is not in use, which most of the time means it wont even loop.

    If I haven't removed the need for this class entirely yet then I've probably left something out.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  2. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  3. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  4. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  5. Replies: 7
    Last Post: 05-26-2005, 10:48 AM