Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to `new` a .NET object aligned to 64 bytes? [duplicate]

There are functions like _aligned_malloc for C and C++ but I can't find anything for aligning .NET objects in memory.

like image 253
Nick Strupat Avatar asked Dec 13 '25 16:12

Nick Strupat


1 Answers

It is not possible in the general case to usefully align a .net object on a 64-bit boundary, because even if an object starts out on a 64-bit boundary there's no guarantee that it won't be relocated to an odd multiple of 32 bits. For some reason, .net seems to think it's worthwhile to force arrays of more than a thousand double values to the Large Object Heap, which is always 64-bit aligned but is otherwise horrible, and yet provides no useful means of requesting 64-bit alignment for other objects even though doing so should not be difficult or costly (round up object sizes in gen0; when moving objects to higher-numbered generations, pair up odd-sized objects).

like image 143
supercat Avatar answered Dec 15 '25 06:12

supercat