skip to Main Content

I’m making a gomoku artificial intelligence and I was wondering myself wich was the best optimized thing to do to have my table available in all my functions. This table is under the form of a char map[MAPSIZE][MAPSIZE]. In my algorithm I a lot of read access to this table.

Is it faster to access this map if it’s passed as:

  • An argument in all my functions.
  • A member of my algorithm class.
  • A global variable.
  • An argument to function but as a pointer.

In a near future I will have to make a lot of copies of this table to implement a search tree.

Thanks for your time,

2

Answers


  1. If it makes sense for it to be a class member – make it a class member. This is a design decision that shouldn’t be made out of optimization considerations (at least not yet, you can later, after measuring, trade-off design for performance if you think it’s worth it).

    The alternative is passing it by reference (or pointer, but reference is more C++-ish).

    Login or Signup to reply.
  2. Is it faster to access this map if it’s passed as: …

    Different methods do incur different runtime costs. However, the difference is almost certainly irrelevant unless you do something grossly inefficient (e.g. unnecessarily copy the entire table in each method).

    I suggest you design this with correctness and clarity in mind, and worry about optimizations later.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search