View Single Post
  #2 (permalink)  
Old February 21st, 2011, 06:13 PM
DrPurdum DrPurdum is offline
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default ragged arrays

You understand it correctly. The difficult part to understand for most people is the idea that the second element subscript is actually just an lvalue. The second set of statements:

samples[0] = new int[count1];

is simply filling in the lvalue with a pointer to an array of 3 ints. The next statement simply fills in a pointer to an array of 10 ints, and so on.

Therefore, the data look exactly as you understand it. About the only thing you can't assume is that all elements of the array are contiguous. In actual fact, Windows is free to scatter those three arrays (i.e., samples[0][0], samples[1][0], and samples[3][0]) anywhere it wants in memory space.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)