Right, so how can i modify this program so it only uses virtual memory? alternatively how else can i prove that
1. Accessing virtual memory column by column is slower than row by row.
2. These two accesing techniques make no difference to memory access time of main memory?
I have made a table in excel already and some graphs from the data. These basically show that column by column time is always longer. It also shows that column by column time actually decreases just before the system crashes! Some dude above has told me why, but I need to prove this theory mathmatically or by modifying the program and creating a new table & graphs. Windows won't let me have zero virtual memory. Any suggestions? I would be more than happy to supply the table & graphs if you want.
Yes, if you run the program below enough times it will freeze up your computer. Be careful, dont let it run any bigger than your total memory (physical + virtual)
here is the program, thanks for your time:
Code:
/*************************************************************************
RowCol.c
Experiment on row/column access to an array
*************************************************************************/
#include <stdio.h>
#include <conio.h>
#include <sys/timeb.h>
#include <windows.h>
void WaitUser();
unsigned long IntervalTimer();
int n;
/*
This commented out main() can be used to assess the accuracy of the IntervalTimer()
void main()
{
unsigned long msecs;
unsigned long secs;
printf("Enter interval time (secs): ");
scanf("%i",&secs);
n = 0;
printf("\nn = %d\n",n);
while(1){
n++;
IntervalTimer();
Sleep(secs*1000);
msecs = IntervalTimer();
printf( "n = %d Time seconds:\t%ld mseconds: \t%ld \n",n,msecs/60,msecs%60);
}
}
*/
void main()
{
char **Array;
int n=0;
int Row=16;
int Column=16;
int b;
int r,c;
int i;
unsigned long RCTime, CRTime;
for(i = 0; i < 12; i++){
printf("\nArray size %d (%d x %d) ", Row*Column,Row, Column);
Array=(char**)malloc(Row*sizeof(char*));
for (b=0;b<Row;b++)
Array[b]=(char*)malloc(Column*sizeof(char));
IntervalTimer();
for(r=0;r<Row;r++)
for(c=0;c<Column;c++)
Array[r][c]=1;
RCTime = IntervalTimer();
IntervalTimer();
for(c=0;c<Column;c++)
for(r=0;r<Row;r++)
Array[r][c]=1;
CRTime = IntervalTimer();
printf(" RCTime(ms) %d CRTime(ms) %d ratio %f",
RCTime, CRTime, (float)CRTime/(float)RCTime);
for (b=0;b<Row;b++)
free(Array[b]);
free(Array);
Row *= 2; Column *= 2;
printf(" Hit any key to continue");
WaitUser();
}
}
///////////////////////////////////////////////////////////
// IntervalTimer
// Measures a (single) simple time interval in msecs
// First call starts the interval, second call ends the
// interval and returns the interval length in msecs
///////////////////////////////////////////////////////////
#define START 0
#define STOP 1
unsigned long IntervalTimer()
{
static int StartStop = START;
static struct _timeb tstructstart;
static struct _timeb tstructstop;
int msecs;
unsigned long secs;
if(StartStop == START){
_ftime(&tstructstart);
StartStop = STOP;
return 0;
}
else{
_ftime(&tstructstop);
msecs=tstructstop.millitm-tstructstart.millitm;
secs=tstructstop.time-tstructstart.time;
if (msecs<0) {msecs=1000+msecs;secs--;}
StartStop = START;
return secs*60 + msecs;
}
}
void WaitUser()
{
fflush(stdin);
while(!kbhit());
getch();
//fflush(stdin);
}