Click here to Skip to main content
15,921,716 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralInclude headers. Pin
Neha30-Mar-04 20:24
Neha30-Mar-04 20:24 
GeneralRe: Include headers. Pin
Prakash Nadar30-Mar-04 20:30
Prakash Nadar30-Mar-04 20:30 
GeneralRe: Include headers. Pin
Neha30-Mar-04 20:44
Neha30-Mar-04 20:44 
GeneralRe: Include headers. Pin
Cedric Moonen30-Mar-04 21:34
Cedric Moonen30-Mar-04 21:34 
GeneralRe: Include headers. Pin
22491730-Mar-04 22:14
22491730-Mar-04 22:14 
GeneralMSFlexGrid properties Pin
catngo30-Mar-04 20:09
catngo30-Mar-04 20:09 
GeneralRe: MSFlexGrid properties Pin
22491730-Mar-04 22:26
22491730-Mar-04 22:26 
GeneralRe: MSFlexGrid properties Pin
catngo31-Mar-04 14:38
catngo31-Mar-04 14:38 
QuestionHow does CListCtrl Arrange work? Pin
Anonymous30-Mar-04 19:49
Anonymous30-Mar-04 19:49 
AnswerRe: How does CListCtrl Arrange work? Pin
Anonymous31-Mar-04 16:31
Anonymous31-Mar-04 16:31 
Generalabout sockets Pin
amir_iiui30-Mar-04 19:21
amir_iiui30-Mar-04 19:21 
GeneralRe: about sockets Pin
22491730-Mar-04 19:31
22491730-Mar-04 19:31 
GeneralOnOK() Pin
ykg888@yahoo.com30-Mar-04 18:55
sussykg888@yahoo.com30-Mar-04 18:55 
GeneralRe: OnOK() Pin
Prakash Nadar30-Mar-04 20:26
Prakash Nadar30-Mar-04 20:26 
GeneralRe: OnOK() Pin
David Crow31-Mar-04 2:37
David Crow31-Mar-04 2:37 
GeneralTAPI related Pin
Ahmed Jahanzeb30-Mar-04 17:58
sussAhmed Jahanzeb30-Mar-04 17:58 
GeneralRe: TAPI related Pin
Michael P Butler30-Mar-04 21:59
Michael P Butler30-Mar-04 21:59 
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

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.