Fix the `write` function in `MemoryAllocation`, which has a buffer overflow bug. Do not throw an exception if the buffer is full; just write as much as possible. 
