From: <hba...@ma...> - 2006-07-28 22:53:30
|
On Jul 28, 2006, at 6:15 PM, Jerry wrote: > > How does C map 2D arrays such as PLFLT **z to memory (e.g. plmesh)? > Is this an array of pointers that then each point to the first > element of a row (column??) of z, or is this simply a pointer to a > pointer to z[0, 0] which merely needs to be twice de-referenced? PLFLT **z is an array of pointers each of which point to the first element of a row/column. > Let me try to be even more confusing. Say z is M x N. Is the address > that is pointed to by PLFLT **z the first byte of a blob of memory > that is M*N*sizeof(int), with M and N used in parsing up this blob > into addressable array elements? Or are there actually M pointers to > M memory locations, each of which represents N array elements as a > contiguous blob of memory amounting to N*sizeof(int) bytes? If the > latter is true, then it seems that z would require M*N*sizeof(int) > +M*sizeof(pointer) bytes, and somehow this seems weird. If the latter It does allow you to use M non-contiguous blocks of memory of size N * sizeof(int), rather than one large contiguous block of size M*N*sizeof(int). This might have been handy back in the day when computers had small fragmented memories :). -Hazen |