lookup tables

Discussion in 'C Programming' started by junky_fellow@yahoo.co.in, May 18, 2005.

  1. Guest

    what are lookup tables ? How can they be used to optimise the code ?
     
    , May 18, 2005
    #1
    1. Advertising

  2. Ravi Uday Guest

    Ravi Uday, May 18, 2005
    #2
    1. Advertising

  3. jacob navia Guest

    wrote:
    > what are lookup tables ? How can they be used to optimise the code ?
    >

    Please do your own homework.

    You have posted all the questions of your homework here:
    1: padding between variables in a structure
    2: Multiple return statements Vs goto's
    3: wrinting an optimised code
    4: register variables
    5: doubt related to string pointers.
    6: which is better "switch" or "if-else"
     
    jacob navia, May 18, 2005
    #3
  4. Guest

    jacob navia wrote:
    > wrote:
    > > what are lookup tables ? How can they be used to optimise the code

    ?
    > >

    > Please do your own homework.
    >
    > You have posted all the questions of your homework here:
    > 1: padding between variables in a structure
    > 2: Multiple return statements Vs goto's
    > 3: wrinting an optimised code
    > 4: register variables
    > 5: doubt related to string pointers.
    > 6: which is better "switch" or "if-else"


    I did search the answers on net but got confused more and more.
    So, I thought to post them here.
     
    , May 18, 2005
    #4
  5. Ravi Uday wrote:
    >
    >
    > wrote:
    >
    >> what are lookup tables ? How can they be used to optimise the code ?
    >>

    > Its mainly used for bit fiddling.
    > See the FAQ's - 20.12 and 20.13
    > @ http://www.eskimo.com/~scs/C-faq/top.html
    >
    > - Ravi
    >

    Wrong.
    Many trigonomy (sp?) functions, such as sine and
    tangent are implemented using lookup tables. To
    my knowledge, this is not bit twiddling; but a
    fast method for obtaining a result.


    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
     
    Thomas Matthews, May 18, 2005
    #5
  6. wrote:

    > what are lookup tables ?

    Lookup tables are tables consisting of data either
    with a key in the record or an implied key (such
    as an array).

    > How can they be used to optimise the code ?

    Many times, lookup tables are used to implement
    a function which would take more time to calculate
    using a formula. A classic example is the sine
    function.

    Another usage of lookup tables is to convert values.

    A lookup table can also be used for authentication.


    As far as optimization goes, lookup tables trade
    memory space for execution speed. Sometimes they
    trade execution speed for ease of maintenance or
    change.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
     
    Thomas Matthews, May 18, 2005
    #6
  7. Ravi Uday Guest

    Thomas Matthews wrote:

    > Ravi Uday wrote:
    >
    >>
    >>
    >> wrote:
    >>
    >>> what are lookup tables ? How can they be used to optimise the code ?
    >>>

    >> Its mainly used for bit fiddling.
    >> See the FAQ's - 20.12 and 20.13
    >> @ http://www.eskimo.com/~scs/C-faq/top.html
    >>
    >> - Ravi
    >>

    > Wrong.
    > Many trigonomy (sp?) functions, such as sine and
    > tangent are implemented using lookup tables. To
    > my knowledge, this is not bit twiddling; but a
    > fast method for obtaining a result.
    >

    Did you read the FAQs i had pointed ??

    Most common usage of
    look-up table that i have seen
    is when using a series of function-pointers
    which gets invoked based on some input.
    There were some sample code posted here some time back :)

    - Ravi



    >
     
    Ravi Uday, May 18, 2005
    #7
  8. Alan Balmer Guest

    On Wed, 18 May 2005 10:50:10 +0530, Ravi Uday <>
    wrote:

    >
    >
    > wrote:
    >> what are lookup tables ? How can they be used to optimise the code ?
    >>

    >Its mainly used for bit fiddling.


    Hardly. Lookup tables have many uses. For optimization you might think
    of a lookup table as a list of precalculated values, for applications
    where it is faster to look up a value than calculate it.

    --
    Al Balmer
    Balmer Consulting
     
    Alan Balmer, May 18, 2005
    #8
  9. On 17 May 2005 22:11:40 -0700, wrote:


    >what are lookup tables ? How can they be used to optimise the code ?


    On some machines, they can't. On Cray's, for example, it's faster to
    calculate bit values than look them up in a table. You're micro-optimizing
    again.


    --
    #include <standard.disclaimer>
    _
    Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
     
    Kevin D. Quitt, May 18, 2005
    #9
  10. Eric Sosman Guest

    Thomas Matthews wrote:
    > Ravi Uday wrote:
    >
    >>
    >>
    >> wrote:
    >>
    >>> what are lookup tables ? How can they be used to optimise the code ?
    >>>

    >> Its mainly used for bit fiddling.
    >> See the FAQ's - 20.12 and 20.13
    >> @ http://www.eskimo.com/~scs/C-faq/top.html
    >>
    >> - Ravi
    >>

    > Wrong.
    > Many trigonomy (sp?) functions, such as sine and
    > tangent are implemented using lookup tables. To
    > my knowledge, this is not bit twiddling; but a
    > fast method for obtaining a result.


    "Trigonometry." Easy to remember: "metry" is "measurement"
    and "trigons" are "three-sided polygons," i.e. "triangles."
    "Trigonometry" is "the measurement of triangles."

    This is an interesting (or mildly interesting) topic in the
    history of computing. In the Very Early Days when computational
    power was remote, expensive, and slow, the economically effective
    thing to do was to print tables of trigonometric functions, often
    with "proportional parts" in the margins to assist more accurate
    interpolations. Later, when automatic computers showed up, the
    State of the Art switched to approximations by polynomials or
    ratios of polynomials: the new machines didn't have much memory
    for storing tables, but could grind out the computations at a
    good enough rate to make themselves useful. Then memories got
    larger, and it was back to the tables again: the computer would
    store a fairly coarse table and use second- or even third-degree
    methods to interpolate with good accuracy. Today the CPUs are
    faster than the memory, so the practice has reverted to purely
    computational methods. Tomorrow ... well, "Tomorrow and tomorrow
    and tomorrow, creeps!" We do not know what tomorrow's economics
    may bring to the practice of computing. What we *do* know is that
    the Right Way has switched from A to B and back to A and again
    to B -- and hence "conventional wisdom" is not a good predictor.

    I personally wrote table-based trig functions as recently as
    1979 (using one full circle == 65536 "bam," or "binary angular
    measurement"). I would not do so today -- but I might do so
    tomorrow; who knows where technological trade-offs may take us?
    If the history of computing teaches us anything, it teaches that
    we are in a fashion-driven industry -- and we don't know what
    tomorrow's hemline lengths will be.

    --
    Eric Sosman
     
    Eric Sosman, May 19, 2005
    #10
  11. Richard Bos Guest

    Ravi Uday <> wrote:

    > Thomas Matthews wrote:
    >
    > > Ravi Uday wrote:
    > >
    > >> wrote:
    > >>
    > >>> what are lookup tables ? How can they be used to optimise the code ?
    > >>>
    > >> Its mainly used for bit fiddling.
    > >> See the FAQ's - 20.12 and 20.13
    > >> @ http://www.eskimo.com/~scs/C-faq/top.html


    > > Wrong.
    > > Many trigonomy (sp?) functions, such as sine and
    > > tangent are implemented using lookup tables.
    > >

    > Did you read the FAQs i had pointed ??


    I did. Those FAQs mention that bit twiddling is often implemented using
    lookup tables. This does not mean that bit twiddling is the most
    important thing lookup tables are used for at all. That's taking the
    relationship the wrong way 'round.

    Richard
     
    Richard Bos, May 19, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Demetri
    Replies:
    0
    Views:
    341
    Demetri
    Oct 15, 2003
  2. Jack
    Replies:
    0
    Views:
    365
  3. Adrian Charteris

    XSLT Lookup Tables Help.

    Adrian Charteris, Oct 15, 2004, in forum: XML
    Replies:
    4
    Views:
    956
    Adrian Charteris
    Oct 18, 2004
  4. John Collyer

    Function lookup tables?

    John Collyer, Oct 4, 2003, in forum: C++
    Replies:
    12
    Views:
    1,303
    Karl Heinz Buchegger
    Oct 6, 2003
  5. Replies:
    6
    Views:
    309
Loading...

Share This Page