Linux, programming, computers and life

February 11, 2007

do not overuse memset

Filed under: programming, c++

Just a reminder. C++ is not C. memset is a useful function (you know, take-memory-location-and-length-and-fill-it-with-char). But there’s no reason whatsoever to use it in order to reset an object. Define a Reset() method (or choose your own name) and use it.
I’m not just saying it. It’s coming from a frustrated person after looking for a memory bug for day and a half. The bug was memset which reset some variable which was used in other memset and reset a lot of memory this way.
Two lessons learned:

  1. memset is for buffers, not for objects
  2. electric fence is really helpful

Technorati Tags: , , , ,

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers