Click here to Skip to main content
15,905,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: TAPI related Pin
Filomela5-May-04 5:18
Filomela5-May-04 5:18 
GeneralInteresting problems Pin
FlyingDancer30-Mar-04 15:08
FlyingDancer30-Mar-04 15:08 
GeneralRe: Interesting problems Pin
Maxwell Chen30-Mar-04 16:24
Maxwell Chen30-Mar-04 16:24 
GeneralRe: Interesting problems Pin
FlyingDancer30-Mar-04 18:45
FlyingDancer30-Mar-04 18:45 
GeneralRe: Interesting problems Pin
ohadp30-Mar-04 19:16
ohadp30-Mar-04 19:16 
GeneralRe: Interesting problems Pin
FlyingDancer30-Mar-04 21:39
FlyingDancer30-Mar-04 21:39 
GeneralRe: Interesting problems Pin
Maxwell Chen30-Mar-04 22:20
Maxwell Chen30-Mar-04 22:20 
GeneralRe: Interesting problems Pin
Paul Ranson31-Mar-04 1:57
Paul Ranson31-Mar-04 1:57 
1. I don't know, other than it's likely to be a virtual memory pathology.

2. This is your code,
<br />
// v1<br />
for ( j = 0; j< N; j++ )<br />
{<br />
        for ( i = 0; i < N; i++ )<br />
	{<br />
                slice [i][j] = (float)(slice[i][j] + 0.01 ) ;<br />
        }<br />
}<br />
// which is equivalent to<br />
for ( j = 0; j< N; j++ )<br />
{<br />
        for ( i = 0; i < N; i++ )<br />
	{<br />
                float * pf = slice + ( i * N ) + j ;<br />
                *pf += 0.01 ;<br />
        }<br />
}<br />
<br />
// v2<br />
for ( j = 0; j< N; j++ )<br />
{<br />
        for ( i = 0; i < N; i++ )<br />
	{<br />
                slice [j][i] = (float)(slice[j][i] + 0.01 ) ;<br />
        }<br />
}<br />
// which is equivalent to<br />
for ( j = 0; j< N; j++ )<br />
{<br />
        float * pf = slice + (j * N) ;<br />
        for ( i = 0; i < N; i++ )<br />
	{<br />
                *pf += 0.01 ;<br />
                ++pf ;<br />
        }<br />
}<br />

IOW in the first example you are asking the CPU to do an extra multiplication each time around the inner loop. The optimiser may be able to turn it into an addition (if that's faster...), but it's still extra work.

More subtley the second example accesses memory consecutively, so the data is much more likely to be in the CPU cache, whereas the first accesses every N * sizeof ( float ) bytes which means the next value will never be in the cache, accessing main memory means waiting about, accessing the cache puts that off, and since the cache is read and written to main memory in relatively large chunks you will get an entire 'cache line' of modified values going to main memory in the same time as it takes to write one.

Anyway it would be worth examining the generated machine code for each example to see what the optimiser actually does, and perhaps play with the options.

3. The default stack size for Win32 is 1MB. You are asking to allocate 4MB (sizeof ( float ) == 4 ) so the only way is to exit with an exception. You can adjust this in the linker, or with EditBin, but for a data structure of this nature either declaring it statically as in your example or allocation on the heap as in Maxwell's is appropriate.

Paul
GeneralRe: Interesting problems Pin
FlyingDancer31-Mar-04 13:30
FlyingDancer31-Mar-04 13:30 
GeneralC to Visual C++.Net Pin
gyrogearloose30-Mar-04 15:04
gyrogearloose30-Mar-04 15:04 
GeneralRe: C to Visual C++.Net Pin
Christian Graus30-Mar-04 15:14
protectorChristian Graus30-Mar-04 15:14 
GeneralRe: C to Visual C++.Net Pin
Maxwell Chen30-Mar-04 15:37
Maxwell Chen30-Mar-04 15:37 
GeneralRe: C to Visual C++.Net Pin
Christian Graus30-Mar-04 15:38
protectorChristian Graus30-Mar-04 15:38 
GeneralRe: C to Visual C++.Net Pin
Maxwell Chen30-Mar-04 15:46
Maxwell Chen30-Mar-04 15:46 
GeneralRe: C to Visual C++.Net Pin
gyrogearloose31-Mar-04 13:23
gyrogearloose31-Mar-04 13:23 
GeneralRe: C to Visual C++.Net Pin
gyrogearloose31-Mar-04 14:03
gyrogearloose31-Mar-04 14:03 
GeneralCImageList serialization under XP and NT Pin
Heywood30-Mar-04 13:41
Heywood30-Mar-04 13:41 
GeneralRe: CImageList serialization under XP and NT Pin
Michael Dunn30-Mar-04 14:47
sitebuilderMichael Dunn30-Mar-04 14:47 
QuestionWinXP : how to hide my console-app from the taskbar ? Pin
L.Denninger30-Mar-04 11:43
L.Denninger30-Mar-04 11:43 
AnswerRe: WinXP : how to hide my console-app from the taskbar ? Pin
Christian Graus30-Mar-04 14:03
protectorChristian Graus30-Mar-04 14:03 
AnswerRe: WinXP : how to hide my console-app from the taskbar ? Pin
Prakash Nadar30-Mar-04 15:03
Prakash Nadar30-Mar-04 15:03 
AnswerRe: WinXP : how to hide my console-app from the taskbar ? Pin
gUrM33T31-Mar-04 17:14
gUrM33T31-Mar-04 17:14 
GeneralClose dialog box on loss of focus Pin
Anonymous30-Mar-04 11:25
Anonymous30-Mar-04 11:25 
GeneralRe: Close dialog box on loss of focus Pin
l a u r e n30-Mar-04 15:22
l a u r e n30-Mar-04 15:22 
GeneralRe: Close dialog box on loss of focus Pin
Anonymous30-Mar-04 23:58
Anonymous30-Mar-04 23:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.