Memory Stomp

The residents of Struct B needed to have a picture taken for the magazine.

You sent someone to take the photo and submit it to the editor.

A short time later, the magazine complained that the picture had only six people in it, but they had a list of seven names.

You sent the photographer back to try again. The magazine complained again. “It’s as if Mr. N doesn’t exist. He’s just not there.” The photographer swore up and down that all of the residents were present for the photo.

You decided to see for yourself what was going on.

The struct had a nice foyer that was the perfect place for a photo, you were told. The residents gathered just as they had before, in a row spanning the foyer area.

Just as you pressed the button to take the photo, Ms. L moved directly in front of Mr. N. The resulting image had no trace of Mr. N.

“Let’s try that again,” you said, and the residents rearranged themselves as before. Again, just as you pushed the button, Ms. L was in front.

“What’s going on here?” you asked. Ms. L explained that when the picture was being taken, she suddenly felt like she didn’t have enough room – she needed to move to a position where she would have enough space.

The foyer was not quite wide enough for all of them to stand straight across, and in preparing for the photo, Ms. L would be turned sideways a bit. This felt wrong to her quite suddenly when the actual photo was being taken.

It was like she was erasing the memory of Mr. N, who stayed in place, but could no longer be seen.

You knew what the answer was. You found a nice spot in the much larger living room where everyone felt like there was plenty of space.

This time, the photo showed every resident of Struct B.

If variables don’t have enough memory allocated, they can potentially write over the memory allocated to other variables.

This entry was posted in Code and tagged . Bookmark the permalink.

Leave a Reply