Proposal: Explicit uses of slices for memory management, both automatic and manual

Hi, I made this issue a long time ago, and I sort of stumbled my way around it. It took me a while and a few pain points to figure out what I wanted. Here was my issue, although it is not relevant to the discussion too much other then ‘it existed’ Slices and memory allocation as well methods to read and write inside structs. · Issue #14141 · crystal-lang/crystal · GitHub

I know this is a big ask, but I think this will be very helpful to the language, for both automatic and manual memory management uses.

What if you can store slices by reference/value depending on the type of data, and use them like points, with explicit allocation/deallocation life times? I want to store slices to different variable types for primitive optimization with game development. I am currently playing around with Raylib and SDL on the C Side, and also the crystal version of Raylib.

I also was wondering of the possibility of using slices with the garbage collector, sort of referencing counting to a hash of memory addresses. If you say save a proc to a slice, you can get the address in memory for that value. I was thinking that, but tied to direct mapping of slice/slices (if it is a big 'pass by reference, I would expect there to be multiple addresses but I could be wrong.). Out of curiousity, which would be more in line with the crystal development teams vision for the language?

Anyway, related, but I am sort of using this for game development, but ideally, I would like to make as efficient and optimized software as I can; hence the idea. I think Slices can be used in either way to optimize and fine-tune memory. What do you all think? I know either is a big ask, but curiosity killed the cat for me lol. Go ahead and tell me if the idea/ideas are good/bad.

Thank you. I can provide code snippets on what I want if asked for the standard lib docs/my own imagination.

I think having those snippets would help making the point :pray:

PS: Welcome!