Maps pros and cons

Maps are giving me headaches…
I’m not even sure what their main purposes are…
Used to hear …they are like containers but indexed.
Were they useful in old versions and the memory tables could replace them now in ax2012?
Could you give me a short blur for the pros and cons for ax3 and ax2012?

Thanks

You probably mean the Map class (there are also maps in Data Dictionary). The Map class is similar to container in that sense that both can contain collection of objects, but there are many differences. Container can contain values of any primitive type and elements can be accessed by index. Map contains two values - key and the actual value. Types are defined on Map construction and values of other types are not accepted. Note that Map is a class (not a primitive types as container) and can refer other objects.

You can find maps in other languages, often with more descriptive names: dictionary, associative array, hash table etc. (you can use your favorite search engine to find more details).

You can use a Map at any time when you need to store a value with a given key in memory - e.g. when you want to remember calculated results for a set of input values (so you can reuse results without repeated calculation), you’re mapping users to machines or whatever.

InMemory temporary tables exist in older versions of AX as well, but you can’t easily construct tables with columns of given types at runtime and you can’t store objects there. Even in cases when it would be applicable, using temporary tables would be slower than using a Map, because tables are heavier and actually saves data to disk when they get bigger. On the other hand, they may be a good choice if your Map would be too big to be held in memory. As usual, you have several tools and you have to use them at the right time.

How much faster would it be? Cause I would prefer debug code with temporary tables more than Maps. Don’t you think?

I don’t know the exact difference when a temporary table is in memory - you can measure it by yourself if you want. But the different between accessing hard disk and RAM should be obvious. (Temporary tables are saved to disk if they exceed certain size - 128 KB, I think).

I’ll try do some benchmarking later on…[Y]