In JavaScript, there exists a type, Uint8Array. This type allows you to store a array of some size filled with bytes. This provides a memory-compact way to store raw binary data rather than arrays. I would like a library (along with a extension JS file for the JS part, in Snap!) that allows you to create and modify these arrays.
Lets take one use case; a emulator, specifically ROM/RAM for it. Normally most architectures use a big area filled with bytes, of course; you know this. Now in Snap! you might want to describe this with a list that defaults to zeros spanning across the data size you need. But this is inefficient for many reasons:
- It has to be a Snap! list. This is a small wrapper, yet it does add more memory.
- Even under Snap!'s List class the JS array itself is meant for dynamic adding/removing, not a raw array (like in C where you do something like
type array[size];) - Each element is a whole float (not just a single byte!)
So for this use case, a Uint8Array would be very VERY useful! It would also allow you to save the memory or such. Now there is, of course; way more use cases. But this one is a important one. With Uint8Array you would also be able to read/write random binary formats (kind of a niche use case, but might be nice for loading formats Snap! doesn’t support).
Now how would you implement this? Of course in Snap! it would be a seperate extension JS file that create extensions, and the library to complement that. But for now, I made this little proof-of-concept (might be buggy and doesnt have all the features I want, but it works):
Hope this gets added to Snap!, sometime (probably not during the Snap! v12 lifecycle, but maybe in the future Snap! v13??) :~)