c - How to access multiple elements of array in one go? -



c - How to access multiple elements of array in one go? -

i have array uint8_t data[256]. each element single byte. info bus 32 bit long. so, if want access 32 bits, do:

data = data[i]+(data[i+1]<<8)+(data[i+2]<<16)+(data[i+3]<<24);

but translates 4 separate read requests in memory of 1 byte each.

how can access 4 bytes in form of 1 transaction?

if know endian-ness of info (or if don't care), , info aligned (or have byte-addressing process , don't care efficiency) can cast info uint32_t * , access in 4-byte chucks, so:

data = ((uint32_t *)data)[i/4];

this of course of study assumes i multiple of 4.

c arrays

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -