Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC++ MVC framework for Linux/Motif Pin
Leif Simon Goodwin25-Apr-13 6:35
Leif Simon Goodwin25-Apr-13 6:35 
AnswerRe: C++ MVC framework for Linux/Motif Pin
pasztorpisti25-Apr-13 20:56
pasztorpisti25-Apr-13 20:56 
QuestionCrystal Reports 2011 with C++/MFC Dev Studio 2010 Pin
Member 983646924-Apr-13 18:42
Member 983646924-Apr-13 18:42 
QuestionAudio in DirectShow Pin
Sachin k Rajput 24-Apr-13 17:40
Sachin k Rajput 24-Apr-13 17:40 
AnswerRe: Audio in DirectShow Pin
Vaclav_25-Apr-13 3:03
Vaclav_25-Apr-13 3:03 
QuestionHow to create 4 dimenstional array Pin
jothivel k24-Apr-13 9:07
jothivel k24-Apr-13 9:07 
AnswerRe: How to create 4 dimenstional array Pin
Richard MacCutchan24-Apr-13 9:33
mveRichard MacCutchan24-Apr-13 9:33 
AnswerRe: How to create 4 dimenstional array Pin
pasztorpisti24-Apr-13 9:45
pasztorpisti24-Apr-13 9:45 
The memory layout of a C array like char my_array[4][3][2] is the following (where a '0' character is a placeholder for 1 byte):
first dim=0      first dim=1      first dim=2      first dim=3
00 | 00 | 00  #  00 | 00 | 00  #  00 | 00 | 00  #  00 | 00 | 00
▲    ▲     ▲                      ▲    ▲     ▲
|    |     |                      |    |     |
|    |     [0][2][1]              |    |     [2][2][1]
|    [0][1][0]                    |    [2][1][0]
[0][0][0]                         [2][0][0]

Where '#' means a change in the first index and '|' is a change in the second index, while the 3rd index just moves 1 byte. Because of this memory layout you can make only the first dimension resizable if you are using a pointer instead of a fixed size static array. If you wanted to resize some other dimensions then you should insert bytes in many places but resizing the first dimension means just adding memory at the end of you currently allocated memory, or maybe shrinking the current storage. The above char my_array[4][3][2] could be allocated dynamically in the following way:
C++
typedef char ArrayType[3][2];
ArrayType* p = new ArrayType[4];
p[3][2][1] = 0;

// If you want to resize the first dimension later:
ArrayType* q = (ArrayType*)malloc(sizeof(ArrayType)*4);
q = (ArrayType*)realloc(q, sizeof(ArrayType)*5);
q[4][2][1] = 1;

Note that indexing into p and q are very fast like it is in case of static arrays and the occupied memory is 1 big chunk of continuous area. If you need just 1 resizable dimension then you can go with this technique because it really doesn't matter which dimension has this resizable trait. Lets say you make a 2 dimensional array because you want to store additional data to specific X and Y coordinates. If you need resizable 'Y' dimension then you address the array this way: [Y][X] but if you need resizable 'X' dimension then you simple index this way: [X][Y]. The same applies to multiple dimensions, it really doesn't matter which index do you use for different things, the only 2 things it can screw up is the memory layout of items (cache misses) and the readability of the source code - but sometimes you have to sacrifice readability if you are optimizing because this kind of thing is something that smells like optimization.
GeneralRe: How to create 4 dimenstional array Pin
jothivel k25-Apr-13 7:12
jothivel k25-Apr-13 7:12 
GeneralRe: How to create 4 dimenstional array Pin
pasztorpisti25-Apr-13 20:48
pasztorpisti25-Apr-13 20:48 
AnswerRe: How to create 4 dimenstional array Pin
Stefan_Lang24-Apr-13 22:15
Stefan_Lang24-Apr-13 22:15 
AnswerRe: How to create 4 dimenstional array Pin
Joe Woodbury25-Apr-13 6:47
professionalJoe Woodbury25-Apr-13 6:47 
Questioniso_8583 message Pin
khushboo gupta23-Apr-13 0:16
khushboo gupta23-Apr-13 0:16 
AnswerRe: iso_8583 message Pin
Marco Bertschi23-Apr-13 1:53
protectorMarco Bertschi23-Apr-13 1:53 
GeneralRe: iso_8583 message Pin
khushboo gupta23-Apr-13 20:05
khushboo gupta23-Apr-13 20:05 
GeneralRe: iso_8583 message Pin
Marco Bertschi23-Apr-13 21:39
protectorMarco Bertschi23-Apr-13 21:39 
GeneralMessage Closed Pin
23-Apr-13 20:13
khushboo gupta23-Apr-13 20:13 
GeneralRe: iso_8583 message Pin
Richard MacCutchan23-Apr-13 21:50
mveRichard MacCutchan23-Apr-13 21:50 
GeneralMessage Closed Pin
23-Apr-13 22:54
khushboo gupta23-Apr-13 22:54 
GeneralRe: iso_8583 message Pin
Richard MacCutchan23-Apr-13 23:02
mveRichard MacCutchan23-Apr-13 23:02 
GeneralRe: iso_8583 message Pin
khushboo gupta24-Apr-13 20:17
khushboo gupta24-Apr-13 20:17 
GeneralRe: iso_8583 message Pin
Jochen Arndt24-Apr-13 21:13
professionalJochen Arndt24-Apr-13 21:13 
GeneralRe: iso_8583 message Pin
khushboo gupta24-Apr-13 22:32
khushboo gupta24-Apr-13 22:32 
GeneralRe: iso_8583 message Pin
Richard MacCutchan24-Apr-13 22:58
mveRichard MacCutchan24-Apr-13 22:58 
QuestionMCI wave player Pin
Vijay Ku. Soni23-Apr-13 0:15
Vijay Ku. Soni23-Apr-13 0:15 

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.