Skip to content

Instantly share code, notes, and snippets.

@erans
Forked from ekampf/mem.c
Created October 14, 2018 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erans/e2c9768be5a5153822d454afa87f831e to your computer and use it in GitHub Desktop.
Save erans/e2c9768be5a5153822d454afa87f831e to your computer and use it in GitHub Desktop.
Eran's Interview Question
// Implement a 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