4 ms·
While we are talking about dynamic memory allocation and de-allocation, a useful trick at times is to wrap your mallocator with a bit of code so that you can pr
by jes 4y ago
While we are talking about dynamic memory allocation and de-allocation, a useful trick at times is to wrap your mallocator with a bit of code so that you can program it to fail after, say, n allocations, or on a random basis. In a testing context, this can help you systematically explore the set of possible allocation failures to see if the code handles them as expected.
- saagarjha 4y agoThe vast majority of code cannot so this isn’t particularly useful.
- deleted 4y ago[deleted]
- jes 4y agoIt really depends on context. There are times when it's useful, and times when it's not. It's helped me at times in improving code coverage when developing software for medical devices, so I thought I'd mention it. The technique is can also be generalized beyond just triggering malloc() failures under specified conditions.