Is there a way to mark a chunk of allocated memory readonly?

On most hardware architectures you can only change protection attributes on entire memory pages; you can’t mark a fragment of a page read-only. The relevant APIs are: mprotect() on Unix; VirtualProtect() on Windows. You’ll need to ensure that the memory page doesn’t contain anything that you don’t want to make read-only. To do this, you’ll … Read more

How to debug heap corruption errors?

Application Verifier combined with Debugging Tools for Windows is an amazing setup. You can get both as a part of the Windows Driver Kit or the lighter Windows SDK. (Found out about Application Verifier when researching an earlier question about a heap corruption issue.) I’ve used BoundsChecker and Insure++ (mentioned in other answers) in the … Read more