Re: [personal kdb+] k.h vector accessor function

>G0

it’s a c idiom.

https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

essentially, the K struct is either an atom (t<0) or a header for an array (type in t, length in n).  being a header, it is the first of a chunk of memory, with the rest of the memory (‘content’) described by the header.

part of the reason for making a value all contained in contiguous memory is locality (the info for the value is in one place).  it also simplifies memory management.  it’s certainly possible to use a G* instead of a G, for G0, but that’s not the way kdb+ works so you have to use a K value as declared in k.h.

best,

jack

but in your example:

int main() {


K x;


x=ktn(KI,2);
xI[0]=1;

xI[1]=2;



printf(“intArray[0] = %d, intArray[1] = %d\n”,kI(x)[0] , kI(x)[1]);

/if you want to get a c array into K

doubleArray[0]=3.5;

doubleArray[1]=4.5;

x=ktn(KF,2);

memcpy(x->G0,doubleArray,sizeof(F)*2);


printf(“doubleArray[0] = %f, doubleArray[1] = %f\n”,kF(x)[0] , kF(x)[1]);

// but don’t use malloc/memcpy - use ktn, =, and other functions poking data into arrays


return 0;

}