Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Dynamic vs Static Data

Name: Anonymous 2014-04-27 6:01

Suppose we have

#define SIZE 1024*1024*512
uint8_t dataS[SIZE];
uint8_t *dataD;
/* ... */
dataD = malloc(SIZE);


then
1. how much faster is dataS[index] over dataD[index]?
2. Will CPU's cache amend the indirection?
3. should we strive to make everything global?
4. How global variables affect multi-threading?

Name: Anonymous 2014-04-27 6:06

>>1

One can do "dataD = malloc(SIZE)" and then relocate the executable, but C/C++ doesn't support data/code relocation.

Name: Anonymous 2014-04-27 6:16

>>1

if one keeps dataD pointer in register, then dataD[index] will be faster than the dataS[index] access, because loading 8-byte immediate address is an expensive operation cache-wise (x86 cacheline is 64-bytes). x86 also offers more addressing modes for register base than for an immediate base.

Name: Anonymous 2014-04-27 11:28

>>3
Are you retarded? Modern C compiler can keep both dataD and dataS in registers. There is no apparent performance difference. Only difference in speed could be due to CPU cache, but that depends on if there is other data that is accessed as well (other than dataD and dataS)

>>1
1. Probably no difference. Depends on context.
2. Yes
3. No
4. In no way, if your program is not totally retarded.

Name: Anonymous 2014-04-27 14:25

ITT byte slavery.
Programming isn't about worrying where this or that fucking bit is going to go in the hardware.

Name: Anonymous 2014-04-27 14:58


Don't change these.
Name: Email:
Entire Thread Thread List