Speed of large [] array
- From: "David JD Bell" <davidjdbell@xxxxxxxxxxx>
- Date: Sun, 9 Jul 2006 15:30:11 +1000
With vc7 I am having trouble with large arrays slowing down when I access
the elements more or less randomly. I thought getting an array element was
just pointer arthimatic so would be just a couple of clock ticks regardless
where it is, but the last line in the example shows that random access
really slows down.
I was wondering if large arrays are not allocated contiguous memory, and if
so would I be better making a three dimensional array (of [256][256][256]).
Any advice appreciated, speed is crucial in this case (it's real time image
processing)
BTW this is all compiled in Debug, but it still happens in Release, just a
bit harder to measure becasue it optimised blank loops out.
David Bell
// Declare a big array
bool* DecMat = new bool[16777216];
long x = 0;
// DecMat gets filled, then is used n a loop that gets executed
5,000,000 times
// Times are for the statement executing 5,000,000 times in a loop
// (after subtracting blank looping time, other duties etc)
// small constant index
long ti = 16; // 0ms
bool tb = DecMat [ti]; // 5ms
// large constant index
long ti = 16000000;
bool tb = DecMat [ti]; // 5ms for 5,000,000
// incrementing index
long ti = x++; // 4ms
bool tb = DecMat[ti]; // 10ms
// forumla index
// tcx is a struct{BYTE r,g,b;}; actual r,g,b change constantly
(from a bmp read in loop)
long ti = RGB(tcx->r, txc->g, tcx->b); //
15ms
bool tb = DecMat[RGB(tcx->r, txc->g, tcx->b)]; // 150ms !!!
.
- Follow-Ups:
- Re: Speed of large [] array
- From: David JD Bell
- Re: Speed of large [] array
- From: Alex Blekhman
- Re: Speed of large [] array
- From: Doug Harrison [MVP]
- Re: Speed of large [] array
- Prev by Date: Re: Remove a pointer from list(STL) of pointers
- Next by Date: Re: Speed of large [] array
- Previous by thread: Re: [newbie] OpenMP basic question
- Next by thread: Re: Speed of large [] array
- Index(es):
Relevant Pages
|