Suppose you had to manage your own memory. No 'new', no 'malloc', etc. But you are given one buffer to use, with a fixed size (1,000 bytes here). How do you manage all the requests to get / free memory?
Here is the data structure we use for each memory block:
Next pointer (8 bytes) |
Previous pointer (8 bytes) |
Data size (bytes) (8 bytes) |
Data plus padding up to multiple of 8 bytes |
This visualization is written in Javascript, but an actual implementation would probably be in C.