实际上,为什么我的循环不停止工作?它应该进行大约100次迭代,但不会停止,请帮助。 我拿了min_block_size这是我的缓存1级的10%,而max_block_size这是我的l2缓存内存的10%!执行操作时处理元素到内存块的速度
#include <iostream>
#include <Windows.h>
#include <time.h>
#include <fstream>
#define MIN_BLOCK_SIZE 13108
#define MAX_BLOCK_SIZE 104858
#define STEP 1024
using namespace std;
int main()
{
setlocale(LC_CTYPE, "Russian");
int i, j, c, b;
clock_t c1, c2;
int*p = (int*) malloc(MAX_BLOCK_SIZE);
int tmp = 0;
LARGE_INTEGER start, finish, freq;
c1 = clock();
int n = 0;
for (b = 13108; b < 104858; b = +1024)
{
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&start);
for (c = 0; c <= b; c += sizeof (int))
{
tmp += *(int*) ((int) p + c);
*(int*) ((int) p + c) = tmp;
}
QueryPerformanceCounter(&finish);
double time = (finish.QuadPart - start.QuadPart)/(double) freq.QuadPart;
n++;
cout << "Размер" << n << "блоков:" << (MIN_BLOCK_SIZE + 1024 * (n - 1)) << "KB" << endl;
cout << "Время o6pаботки" << n << "блоков" << time * 1000000 << "мкс" << endl;
cout << "время обработки одного елемента" << time * 1000000000/(MIN_BLOCK_SIZE + 1024 * (n - 1)) << "наносек" << endl;
}
c2 = clock();
cout << "All the time is" << c2 - c1 << "sec";
cin.get();
cin.get();
return 0;
}
'TMP + = *(INT *)((int)的P + C);'有一个很好的机会,指针转换'int'丢失信息,并从阅读(然后写入)你不拥有的内存。使用'int * q = p'和'++ q;'有什么问题? –
您有几个已回答的问题,并且您没有接受答案。解决问题时请接受答案。 –