Like Tree6Likes

Branching vs array indexing

This is a discussion on Branching vs array indexing within the General Discussions forums, part of the Community Boards category; Originally Posted by smokeyangel Didn't sound crazy until I looked up the command pattern -- looks, err, rather heavyweight! wildcard_seven's ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Quote Originally Posted by smokeyangel
    Didn't sound crazy until I looked up the command pattern -- looks, err, rather heavyweight!
    wildcard_seven's particular suggestion is basically the same idea as mapping indices to function pointers in an array, except that the table has keys that are not necessarily just numbers, and they map to function objects rather than function pointers.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    Quote Originally Posted by laserlight View Post
    wildcard_seven's particular suggestion is basically the same idea as mapping indices to function pointers in an array, except that the table has keys that are not necessarily just numbers, and they map to function objects rather than function pointers.
    Oh... ok. That sounds more reasonable. I was looking at Command pattern - Wikipedia, the free encyclopedia as wildcard_seven mentioned "command pattern" and it's what he said, but with a load more decoupling.

    I can see the advantages in looking up functions with a Key rather than an index. I'm afraid I don't see the advantage of function objects over function pointers. [edit] but I see a google search has a few results on this matter.

  3. #18
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Function objects allow the compiler to inline functions bwcause the compiler can see the functions. With pointers, it cannot do this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,282
    Function objects allow the compiler to inline functions bwcause the compiler can see the functions.
    That's true, but in this case the suggestion involved putting instances of a function object with abstract interfaces into a table so the compiler wouldn't be able to see the functions.

    Soma

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. probability branching
    By Dale in forum C# Programming
    Replies: 5
    Last Post: 11-18-2011, 09:32 AM
  2. Minimizing array lookup times using effective indexing...?
    By The Dog in forum Game Programming
    Replies: 5
    Last Post: 02-08-2011, 06:11 AM
  3. Array Indexing w/ strlen()
    By c++_n00b in forum C++ Programming
    Replies: 8
    Last Post: 06-04-2002, 11:18 AM
  4. Branching?
    By Brian in forum C Programming
    Replies: 1
    Last Post: 01-20-2002, 10:06 AM
  5. array indexing
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-01-2001, 11:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21