The big problem is that we are a mixture of C and C++, so there are some places where the memset() and memcpy() are appropriate (on system structures that need to be initialized to zero or that we may not have full implementation details of.)
But all our C++ classes and structures should have a constructor that takes no parameters and builds a properly initialized structure, clear() or init() methods, and a proper copy constructor and operator=(). A lot of cases in the boinc code look like this..... MYCLASS tmpvar; memset(&tmpvar,0,sizeof(tmpvar)); Yuck. A method should never directly access memory owned by an instance of another class. If MYCLASS has allocated memory or virtual methods.... boom. Eric On Thu, Aug 27, 2009 at 12:52 PM, <[email protected]> wrote: > Can we just abolish memset() and memcpy() and let the compiler work it out? > The only time these should ever be used is on a memory buffer of raw bytes. > The compiler could detect the formula "for (i = 0; i < X; ++i) buff[i]=0;" > where buff is an array of a built in type. > > jm7 > > > > Eric J Korpela > <[email protected] > eley.edu> To > Sent by: Nicolás Alvarez > boinc_dev-bounces <[email protected]> > @ssl.berkeley.edu cc > [email protected] > Subject > 08/27/2009 03:41 Re: [boinc_dev] Segfault in > PM boinc_get_init_data. > > > > > > > > > > >> parse_init_data clears the APP_INIT_DATA structure using memset, > corrupting >> the internal structure of the std::string members. >> > > Using memset() and memcpy() on classes or structures in C++ should be > abolished. > > Just preaching to the choir again. > _______________________________________________ > boinc_dev mailing list > [email protected] > http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev > To unsubscribe, visit the above URL and > (near bottom of page) enter your email address. > > > > _______________________________________________ boinc_dev mailing list [email protected] http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev To unsubscribe, visit the above URL and (near bottom of page) enter your email address.
