Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Memory Investigation

  1. Jun 3, 2012 #1
    Hi guys,

    I've been given the code below and asked to explain the data shown in the attached chart. Any ideas? The data shows periodicity, what could explain it? I know it has to do with memory.

    Code (Text):

    -------------------------------------------------------
    #include <iostream>
    #include <fstream>
    #include <ctime>
    #include <stdlib.h>
    #include <math.h>
    #include <windows.h>
    #include <memory.h>

    static LARGE_INTEGER liStart;
    static LARGE_INTEGER liStop;

    using namespace std;

    int main(){
        int n = 10000000;
       
        int k = 0;
        ofstream outFile ("out.txt");
        for (int stepSize = 0; stepSize < 100000; stepSize += 128){
            int * a = new int[n];
            int x = 0;
           
            for (int i = 0; i < n; i += 4096){
                x += a[i+32];
            }
               
            QueryPerformanceCounter(&liStart);
            x=0;       
            for (int i = 0; i < 100; i++){
                x += a[i * stepSize];
            }
            QueryPerformanceCounter(&liStop);      
            outFile << stepSize << '\t' << liStop.QuadPart - liStart.QuadPart<<endl;;
            outFile.flush();
            delete [] a;
        }
       
        return(0);
    }

    -------------------------------------------------------
     
    Thanks,

    Monte
     

    Attached Files:

    Last edited by a moderator: Jun 4, 2012
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted