Article View: comp.lang.c.moderated
Article #2377Re: Freeing Memory
From: Kurt Watzka
Date: Sun, 24 Mar 1996 17:48
Date: Sun, 24 Mar 1996 17:48
49 lines
1889 bytes
1889 bytes
Yourname@somwhere.COM (Your Name) writes:
Do people who are on a first name basis with you just call you "Your"?
> >Node ***nodedata=NULL;
> >int xnodes,ynodes,znodes;
> >
> >Here's how I allocate the array:
> >
> >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]?
Maybe because this will not work? If both "y_dim" and "z_dim" are
compile time constants, you could do something like
Node (* nodedata)[y_dim][z_dim];
nodedata = malloc(sizeof(Node) * x_dim * y_dim * z_dim);
Now you can use the notation proposed by "Your"
>To free use:
>free(nodedata);
>Also, I think I've heard that once the OS has allocated the memory,
>it stays allocated to the process even though the program has
>freed it. The memory is, of course, available for future allocation.
This is true for a lot of systems I know.
Kurt
--
| Kurt Watzka Phone : +49-89-2180-6254
| watzka@stat.uni-muenchen.de
| ua302aa@sunmail.lrz-muenchen.de
Technical Details
Message-ID:
<4j41th$nsf@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4io1ks$nr1@solutions.solon.com> <4j06s3$83j@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: watzka@stat.uni-muenchen.de (Kurt Watzka) Newsgroups: comp.lang.c.moderated Subject: Re: Freeing Memory Date: 24 Mar 1996 11:48:32 -0600 Organization: Leibniz-Rechenzentrum, Muenchen (Germany) Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4j41th$nsf@solutions.solon.com> References: <4io1ks$nr1@solutions.solon.com> <4j06s3$83j@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com