Creating a Segmented Memory Allocator

The Problem statement goes this way,

Create multiple fixed-size buffers (arrays) to act as segments.

(e.g.: I/P: Allocate 10 bytes in Segment A, Allocate 20 bytes in Segment B; O/P: Addresses
allocated in segments)


An top level view on how to Do?
- Create an array of structures, where each structure represents a memory segment with its
own memory buffer and stack top.
- Implement allocate and free functions that take an additional parameter to specify the
segment.
- Inside these functions, use the corresponding segment's stack top to allocate or free
memory.
- Update the stack top for the specified segment when memory is allocated or freed.

Example:
If you allocate 10 bytes in Segment A and 20 bytes in Segment B, each segment's stack top
should move accordingly.


How would you tackle this problem? What actions, end cases, data types, algorithms would you be using while solving this?

Do Type out your Pseudo Solution.
Was this page helpful?