Support for contiguous memory arrays.


#1

I am currently porting over some programs I wrote in C to work in a ulisp environment which utilize public key cryptography (ed25519). The public/private keys are 32 bytes long, and the the signatures are 64 bytes. I’m trying to figure out the best way to handle these in ulisp. I have no need to access the individual bytes, so it feels a bit strange to convert them to ulisp strings or arrays which contain pointers to each byte.

Is there a way in ulisp to have a symbol point to a contiguous array of memory if you know that it will be immutable, and therefore not need to have it’s elements accessed or mutated, and thus can be garbage collected entirely? Alternately, is there FFI function that can point to a C var or function directly that would accomplish this? Has there been thoughts to adding an array type that isn’t a binary tree, call it vector or something, and you give the total length of the array like one does in C?

Am I missing something, or should I just store the values as strings and just leave it there? It feels a bit inefficient both in memory and computation.

Can I store them as keywords?


#2

You could write an extension file that allocates its own C arrays for your public/private keys and signatures, but you’d have to handle garbage collection yourself. If you only have a fixed number of keys and signatures there may be no need for garbage collection.

The advantage of using uLisp arrays or lists is that they integrate with the existing garbage collection mechanism in a simple way. I took advantage of this in my Arbitrary-precision arithmetic extension.


#3

Thanks, I realized that there was very little need to present the keys or signatures to the user for most operations, so I can keep them internal to the C functions that are signing and verifying messages, and storing them to the file system. If a user wants to inspect any part of the byte arrays of the wire protocol, I can just present it to them as uLisp string.

Thanks again for all of your help.