memcpy question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I apologize in advance if this is the wrong message board.  I've noticed
that memcpy seems to take a while (sometimes) for large chunks of memory
(about 1 MB).  

Here's a small sample application:

#include<iostream>
#include<time.h>
#include<cmath>
#include<iomanip>
#include <sys/timeb.h>

using namespace std;

double getTime()
{
  struct timeb tb ;

  ftime ( &tb );
  return (double) tb.time + (double) tb.millitm / 1000.0 ;
}

int main()
{
  char src[1048576] = {0};
  char dst[1048576];
  
  for(unsigned int i = 0; i < 25; ++i)
  {
    double start_time = getTime();
    memcpy(dst, src, 1048576);
    double end_time = getTime();
    cout << "Time: " << 1000.0*(end_time - start_time) << endl;
  }

  return 0;
}

Here's the output:

Time: 0.999928
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0.999928
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0.999928
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0
Time: 0
Time: 1.00017
Time: 0
Time: 0
Time: 0
Time: 0

I would be eternally grateful if anyone could explain what's happening.
Run on a Core 2 Duo E6550, 4 GB RAM.

Thanks,
Mike


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux