reference count for local variable scalar vs vector

Is there something special about reference counting when it comes to scalar local variables inside a function?

It looks like local scalars can share storage of their values with one extra reference (for bookkeeping?)

Local scalar reference counting seems quite different from the local vector counterpart.

: air:perf ; q

KDB+ 3.0 2012.12.04 Copyright (C) 1993-2012 Kx Systems

m32/ 2()core 4096MB hjh air.local 10.0.1.2 PLAY 2013.03.04 

q)a:0

q)b:0

q)c:d:0

q)-16!a

1i

q)-16!b

1i

q)-16!c

2i

q)-16!d

2i

q)f:{la:0; lb:0; lc:ld:0; 0N!-16!la; 0N!-16!lb; 0N!-16!lc; 0N!-16!ld;}

q)f // la lb lc ld seem to “share” 0 and one extra reference

5i

5i

5i

5i

q)f:{la:0; lb:0; lc:ld:1; 0N!-16!la; 0N!-16!lb; 0N!-16!lc; 0N!-16!ld;}

q)f

3i

3i

3i

3i

q)f:{la:0; lb:-1; lc:ld:1; 0N!-16!la; 0N!-16!lb; 0N!-16!lc; 0N!-16!ld;}

q)f

2i

2i

3i

3i

q)f:{la:til 1; lb:til 1; lc:ld:til 3; 0N!-16!la; 0N!-16!lb; 0N!-16!lc; 0N!-16!ld;}

q)f  // local vectors la and lb don’t seem to share

1i

1i

2i

2i

q)

constants used in functions exist from the moment the function is defined (that’s the initial reference, each usage just increments the ref count).

use

value f
to observe constants (and other things). Even if the same constant is used several times, it is defined only once.

Some constants (0,1) are embedded within the byte code itself, revealing differences such as

q){a:2;{-16!2}}

1i

q){a:1;{-16!1}}

2i

creating a vector using til is not using a constant vector. Using a literal will, e.g. a:0 1 2;b:0 1 2;