Click here to Skip to main content
16,010,394 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralDynamic Matrix! Pin
Sunnygirl28-Jun-03 10:54
Sunnygirl28-Jun-03 10:54 
GeneralRe: Dynamic Matrix! Pin
Neville Franks28-Jun-03 11:48
Neville Franks28-Jun-03 11:48 
GeneralRe: Dynamic Matrix! Pin
MAAK28-Jun-03 12:10
MAAK28-Jun-03 12:10 
GeneralRe: Dynamic Matrix! Pin
Toni7828-Jun-03 14:11
Toni7828-Jun-03 14:11 
GeneralRe: Dynamic Matrix! Pin
Peter Weyzen28-Jun-03 17:21
Peter Weyzen28-Jun-03 17:21 
GeneralRe: Dynamic Matrix! Pin
Toni7829-Jun-03 14:42
Toni7829-Jun-03 14:42 
GeneralRe: Dynamic Matrix! Pin
Peter Weyzen29-Jun-03 19:53
Peter Weyzen29-Jun-03 19:53 
GeneralRe: Dynamic Matrix! (I am wrong) Pin
MAAK29-Jun-03 5:40
MAAK29-Jun-03 5:40 
Well I think I didn't think about it correctly, cuz when I think about it again I found that the int ** seems to have better performance than the 1D array implemenation, and it may be not related to how data is near to each other.

The int ** needs 4 mov micro instruction to get the effective address, while the 1D needs 2 mov, one multiplication (which I think more costy and which make the whole overhead) and one addition operation to get the effective address.

This is the assembly code for getting the effective address in the 1D implementation for a matrix 10 x 10 to access element (i, j)
ar[j * w + i] = 5;
mov         eax,dword ptr [j] 
imul        eax,dword ptr [w] 
add         eax,dword ptr [i] 
mov         ecx,dword ptr [ar] 
mov         dword ptr [ecx+eax*4],5 

This is code for the int ** implementation for a matrix 10 x 10
ar[i][j] = 5;
mov         eax,dword ptr [i] 
mov         ecx,dword ptr [ar] 
mov         edx,dword ptr [ecx+eax*4] 
mov         eax,dword ptr [j] 
mov         dword ptr [edx+eax*4],5

however, I found that the the 1D representation is more commonly used for example, this is how the same thing work for a static 2D array declared in the compiler:
ar[i][j] = 5;
mov         eax,dword ptr [i] 
imul        eax,eax,28h 
lea         ecx,ar[eax] 
mov         edx,dword ptr [j] 
mov         dword ptr [ecx+edx*4],5


If you checked it thourougly you will find that it's similar to the 1D, but it has optimization due to previous knowledge of the array size.

[All assembly code is obtained using VC++ debugging disassembly]

This approach is useful in data serializzation since serialization can be done using single call to I/O device, bitmaps for example are stored in memory as a single 1D array.

I hope if anyone has more infomation about this issue shares it with us, cuz am more curios about it.
Generalthe cheapest computer books Pin
chester16328-Jun-03 10:20
chester16328-Jun-03 10:20 
GeneralRe: the cheapest computer books - Beware SPAM Pin
Neville Franks28-Jun-03 11:49
Neville Franks28-Jun-03 11:49 
GeneralRe: the cheapest computer books Pin
Trollslayer28-Jun-03 12:01
mentorTrollslayer28-Jun-03 12:01 
GeneralRe: the cheapest computer books Pin
Toni7828-Jun-03 12:06
Toni7828-Jun-03 12:06 
GeneralTab order in win32 dialog Pin
Melekor28-Jun-03 9:02
Melekor28-Jun-03 9:02 
GeneralRe: Tab order in win32 dialog Pin
Michael Dunn28-Jun-03 9:49
sitebuilderMichael Dunn28-Jun-03 9:49 
GeneralRe: Tab order in win32 dialog Pin
Melekor28-Jun-03 10:21
Melekor28-Jun-03 10:21 
GeneralRe: Tab order in win32 dialog Pin
Neville Franks28-Jun-03 11:51
Neville Franks28-Jun-03 11:51 
GeneralRe: Tab order in win32 dialog Pin
Melekor28-Jun-03 13:38
Melekor28-Jun-03 13:38 
GeneralPrinting in an Area Problem -- Need Help! Pin
Larry J. Siddens28-Jun-03 8:07
Larry J. Siddens28-Jun-03 8:07 
QuestionResource folder? Pin
DaveE9th28-Jun-03 8:05
DaveE9th28-Jun-03 8:05 
GeneralPassing message to thread Pin
Samrah Saulat Mirza28-Jun-03 5:51
Samrah Saulat Mirza28-Jun-03 5:51 
GeneralRe: Passing message to thread Pin
Nitron28-Jun-03 6:02
Nitron28-Jun-03 6:02 
GeneralRe: Passing message to thread Pin
Shah Shehpori28-Jun-03 6:56
sussShah Shehpori28-Jun-03 6:56 
GeneralRe: Passing message to thread Pin
valikac28-Jun-03 6:53
valikac28-Jun-03 6:53 
GeneralRe: Passing message to thread Pin
Shah Shehpori28-Jun-03 6:59
sussShah Shehpori28-Jun-03 6:59 
GeneralRe: Passing message to thread Pin
valikac28-Jun-03 7:46
valikac28-Jun-03 7:46 

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.