From reading this page, it looks to me like you can use the following - for struct
s only though, not class
es (my example would be for Intel CPUs):
[StructLayout(LayoutKind.Sequential, Pack=64)]
I can't see a guarantee anywhere that an object defined in this way will actually be allocated on (or indeed remain on) a 64 byte boundary, but this construct would not be of much use if it wasn't. If you want to check (and I personally most certainly would), there are some suggestions about how to get the address of an allocated object (until it moves!) here:
Memory address of an object in C#
I also can't see any way of not hard-coding the cache line size, but if you're always going to be running your code on Intel CPUs then that shouldn't be a problem, and I think (most) ARM chips also use 64 bytes, although not, apparently, Apple's M1 (huh!, typical).
Of course, if you do this you need to align the corresponding C++ class
/ struct
accordingly. I think it would be wise to hard-code the alignment as 64 bytes there too, don't you? :)