5

I'm trying to find the memory usage of an in-memory table in q. How can I display this?

It is receiving live updates and I would like to keep track of the total used memory of such a table.

I can't seem to find any relevant functions/commands for this. I need something like hcount for file locations, but an in-memory version.

Jean-Paul
  • 19,910
  • 9
  • 62
  • 88

1 Answers1

13

-22! returns the size in bytes of in-memory objects. e.g.

  q)t:([] a:til 1000)
  q)-22!t
8031
  q)/ 1000 longs = 1000*8 bytes + a small header
  q)t:([] a:til 2000)
  q)-22!t
16031

If you are interested in how memory management in kdb works I recommend this tutorial: http://www.timestored.com/kdb-guides/memory-management (Disclaimer: I wrote it.)

Jean-Paul
  • 19,910
  • 9
  • 62
  • 88
Ryan Hamilton
  • 2,601
  • 16
  • 17