🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2379

Re: Freeing Memory

#2379
From: Brian V. McGroarty
Date: Sun, 24 Mar 1996 17:48
36 lines
1571 bytes
Your Name wrote:
>In article <4io1ks$nr1@solutions.solon.com>, dmills@eng.umd.edu says...

[...]


> >nodedata = (Node ***)malloc(sizeof(Node **) * xnodes);
> >for(i = 0;i < xnodes;i++){
> >    nodedata[i] = (Node **)malloc(sizeof(Node *) * ynodes);
> >    for(j = 0;j < ynodes;j++)
> >       nodedata[i][j] = (Node *)malloc(sizeof(Node) * znodes);

[...]


>I've never seen anything like that before!  Assuming all you need is
>a 3D array, why not:

>nodedata = (Node *) malloc(sizeof(Node) * x_dim * y_dim * z_dim);

>then refer to each element as nodedata[i][j][k]?


The size of x_dim, y_dim and z_dim might not be known at compile-time, in
which case the bracket operators would be unusable (only the outer-most
depth may be unknown at compile-time for multi-dimensional arrays without
indirection tables).  Furthermore, third-level depth would need to be
passed along with the pointer to any functions operating on data within a
plane of the 3 dimensional data set.



---
Brian Valters McGroarty -- brianmcg@bix.com
phone/fax (847) 439-7714
Technical Details
Message-ID: <4j41u5$nth@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4j06s3$83j@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: brianmcg@interaccess.com (Brian V. McGroarty)
Newsgroups: comp.lang.c.moderated
Subject: Re: Freeing Memory
Date: 24 Mar 1996 11:48:53 -0600
Organization: Internet Squire
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4j41u5$nth@solutions.solon.com>
References: <4j06s3$83j@solutions.solon.com>
Reply-To: brianmcg@interaccess.com
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: Internet Squire 1.20