| |

VerySource

 Forgot password?
 Register
Search
View: 847|Reply: 5

Access speed of heap / stack / program data area variables?

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 13:00:01
| Show all posts |Read mode
In the era of dos, there are near pointers and far pointers in programs. Near pointers only need to address offset addresses, which is faster. Far pointers also need to cooperate with segment registers when accessing memory.
But for Win32 32-bit flat mode programming, the memory access does not require the cooperation of the segment register or the segment register has changed its use, then the memory access of the stack, heap and global variables in the data area is pure Is there still a difference in access speed? Have you done any experiments in this area?
Reply

Use magic Report

1

Threads

15

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-5 15:30:01
| Show all posts
Learn. . . Look at the expert opinions downstairs
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-5 15:33:01
| Show all posts
attention
Reply

Use magic Report

0

Threads

30

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-1-5 19:03:01
| Show all posts
There is basically no difference ...

// DumpStack.cpp: Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#define MAX_NUMBER_OF_DATA 1000

int g_dataArray [MAX_NUMBER_OF_DATA];

void global ()
{
// Testing ...
LARGE_INTEGER c1, c2;
:: QueryPerformanceCounter (&c1);
for (int i = 0; i <MAX_NUMBER_OF_DATA; ++ i)
{
g_dataArray [i] = i;
}
:: QueryPerformanceCounter (&c2);
printf ("### Global performance count:% I64u\n", c2.QuadPart-c1.QuadPart);
}

void stack ()
{
int dataArray [MAX_NUMBER_OF_DATA];
// Testing ...
LARGE_INTEGER c1, c2;
:: QueryPerformanceCounter (&c1);
for (int i = 0; i <MAX_NUMBER_OF_DATA; ++ i)
{
dataArray [i] = i;
}
:: QueryPerformanceCounter (&c2);
printf ("### Stacking performance count:% I64u\n", c2.QuadPart-c1.QuadPart);
}

void dump ()
{
int * pDataArray = new int [MAX_NUMBER_OF_DATA];
// Testing ...
LARGE_INTEGER c1, c2;
:: QueryPerformanceCounter (&c1);
for (int i = 0; i <MAX_NUMBER_OF_DATA; ++ i)
{
pDataArray [i] = i;
}
:: QueryPerformanceCounter (&c2);
printf ("### Dumping performance count:% I64u\n", c2.QuadPart-c1.QuadPart);
delete [] pDataArray;
pDataArray = NULL;
}

int main (int argc, char * argv [])
{
for (int i = 0; i <100; ++ i)
{
printf ("======= No.% d ======\n", i);
global ();
dump ();
stack ();
}

return 0;
}
Reply

Use magic Report

0

Threads

1

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-1-6 09:18:10
| Show all posts
Follow and learn.
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-4-20 22:00:01
| Show all posts
In fact, there is still a certain gap if the amount of data is magnified another 1,000 times.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list