On Fri, 21 Jan 2011 11:06:20 -0500 (EST) der Mouse <mo...@rodents-montreal.org> wrote:
> > 3. Dynamically allocating data to force its layout on a particular > > memory boundary will require dereferencing a pointer each time you > > need to access that data. You will have better performance if you > > add padding to your data structure, so that layout is determined > > during compile time. > > (a) Sometimes the data structure is dynamically allocated, or at least > accessed via a pointer, anyway. Quite often it's not the whole structure that causes false sharing, but certain members of a structure. So if you allocate those members dynamically you end up with double indirection, e.g. dereference pointer to a structure, then dereference a pointer to a member of a structure. This also increases the number of calls to malloc(), which should be kept to a minimum.