Hi all,
I’ve been working on this functionality for our TorQ framework and wrote a blog about this problem:
http://www.aquaq.co.uk/q/adventure-in-retrieving-memory-size-of-kdb-object/
It has been quite enjoyable working on this and I’ll be excited to see what you guys think about it :)
Best,
WooiKent Lee
Financial Software Developer
AQUAQ Analytics
"This email, its contents and any files attached are a confidential communication and are intended only for the named addressees indicated in the message.
If you are not the named addressee or if you have received this email in error, you may not, without the consent of AquaQ Analytics, copy, use or rely on any information or attachments in any way. Please notify the sender by return email and delete it from your email system.
Unless separately agreed, AquaQ Analytics does not accept any responsibility for the accuracy or completeness of the contents of this email or its attachments. Please note that any views, opinion or advice contained in this communication are those of the sending individual and not those of AquaQ Analytics and AquaQ Analytics shall have no liability whatsoever in relation to this communication (or its content) unless separately agreed"
On Wednesday, November 25, 2015 at 2:32:51 PM UTC, Charles Skelton wrote:
for a vector with no attr, vector capacity is power of 2
`long$2 xexp ceiling 2 xlog 16+elementSize*count
e.g. til 100000000
q)`long$2 xexp ceiling 2 xlog 16+8*100000000
1073741824
see section 42 of http://kx.com/q/d/q.htm for info on attr space usage.
42 Attributes
example overhead
s#2 2 3 sorted 0
u#2 4 5 unique 16*u
p#2 2 1 parted (4\*u;16\*u;4\*u+1)
g#2 1 2 grouped (4*u;16*u;4*u+1;4*n)
The byte overheads use n(number of elements) and u(number of uniques).
Those attr usage numbers need updating for v3.x. I think they would be
u#2 4 5 unique 32\*u
p#2 2 1 parted (8*u;32*u;8*u+1)
`g#2 1 2 grouped (8*u;32*u;8*u+1;8*n)
So for your example
q){long$2 xexp ceiling 2 xlog 16+(8*count x)+sum 8 32 8*count distinct x}t
a
67108864
q){long$2 xexp ceiling 2 xlog 16+8*count x)}t
b
8388608
q)67108864+8388608
75497472
if you’re targeting the general case, ref counting allows same object to be present in multiple containers; observe ref count with -16!x.
This should be sufficient information as a basis for someone to cook up a function that works for any object. If you do, please share it with the community.