Let’s talk a bit about memory management

So after almost finishing my class on operating systems and memory management (at the easy and superficial stuff) i’ve always wondered how one can put all the theorems in a touchable context, and right after i went into the bathtub it hit me.

I’m not talking about memory management methods right now, just if you have no idea about it, think of all the methods you COULD use to fill an array or slice (talking golang now) with other arrays or slices.

The thought is rather easy, let’s say you have an empty slice with len(s) = 32 and you need to fill it with an amount of other slices that are filled with whatever, some random data. The first iteration of data would be pretty straight forward, just putting them at the first free position (concerning it doesn’t exceed the length of the array, in this case 32) – otherwise it should either be rejected or enqueued. Now the fun part begins when you delete random slices from within the slices (e.g., s[0..7] and s[11..14]) and then try to put new data in there.

Now if you’ve got two slices enqeued with len(q[0]) = 4 and len(q[1]) = 8. In case you just put the data in the first fitting (Hint: That’s a keyword) place, there’s no more room for q[1].

This is easily adaptable without even having to get on a lower level of memory management on the OS abstraction level. You can play with this idea – if you’ve got sample implementations of this “problem” (I wouldn’t call it problems, but make of it whatever you want), hit me up so i can link them here 🙂

UPDATE: I did some untested stuff in a go playground, you can play with it. https://play.golang.org/p/ei5QgXBh_7S