Array of struct vs. Struct of array

Discussion created by arsenm on Jun 24, 2011
Latest reply on Jun 25, 2011 by


I'm a bit unsure of the most efficient way to handle a large collection of structs. There are 2 different ways of do it:

Struct of arrays - create a separate buffer for each field

Array of structs - one buffer with the struct as elements


Looking around I've seen some people (mostly talking about Nvidia) saying that it's almost always better to use a struct of arrays. Would this not be true if your struct is one of the fetch sizes (e.g. 128 bits)?

Suppose you have a small struct with a few fields that you will need in close succession and have the same access pattern, and is either 64 or 128 bits wide. Successive threads are reading neighboring structs. For memory coalescing, which approach would be better?