Skip to content

Instantly share code, notes, and snippets.

@ekampf ekampf/mem.c
Last active May 27, 2019

Embed
What would you like to do?
Eran's Interview Question
// Implement a virtual memory manager that takes a large contiguous block of memory and manages allocations
// and deallocations on it.
// The entire buffer needs to be available for allocation. You can use whatever extra memory you need to manage it.
//
// Clearly document design choices, algorithm and possible optimizations.
// While we require you to implement one memory allocation algorithm,
// also document future looking design considerations.
// There are many ways to implement this memory manager. It is important for us to know why you implemented it the way you did,
// whats the pros and cons to your implementation, etc.
//
// While the interface below is written in C, feel free to implement the MemoryManager in the language of your choosing.
// If you need to change the interface due to language limitations (for example, not all languages have pointers)
// or for any other reason - please explain your reasoning for the change.
// For example:
// - if we wanted to use a different memory management strategy, how would we make that change.
// - if we wanted thread safety any other considerations you can think of.
//
// *** Requirements ***
// 1. Working code (obviously).
// 2. Unit tests (using a unit testing library of your choosing)
// 3. Documentation (as describe in the 2nd paragraph above)
//
class MemoryManager {
public:
// buffer is a large chunk of contiguous memory.
// num_bytes is the size of the buffer.
MemoryManager(char * buffer, int num_bytes);
// Allocate memory of size 'size'. Use malloc() like semantics.
char* Alloc(int size);
// Free up previously allocated memory. Use free() like semantics.
void Free(char*);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.