Memory used by kdb objects

By using -22!, we can see the number of bytes used by a kdb object.

On the KX kdb datatypes page, we can also see the size of each datatype:

If 'x' is an atom of type float, we would expect -22!x to return 8.

If 'x' is an atom of type char, we would expect -22!x to return 1.

However, try it and you will discover that this is not the case:

q)-22!1f

17

q)-22!"a"

10

This is due to the fact that a kdb data object contains more than just the actual data. Other metadata is stored - including the type, the attribute (if any), the reference count and the length.

For single item objects, the size of this metadata amounts to 9 bytes. For lists, it amounts to 14 bytes:

q)-22!1#1f

22

q)-22!1#"a"

15