www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/18/12:46:45

From: "Martin Ambuhl" <mambuhl AT tiac DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: big matrix/array
Date: Sat, 18 Jul 1998 12:31:38 -0400
Organization: Nocturnal Aviation
Lines: 60
Message-ID: <6oqiho$r6u@news-central.tiac.net>
References: <35D0C6B0BF1 AT cyberlib DOT itb DOT ac DOT id.> <35AAEC96 DOT 2893C89E AT cartsys DOT com> <35b0151a DOT 9633555 AT news DOT rmi DOT net> <6opo4m$8nv AT news-central DOT tiac DOT net> <35B0ADBC DOT 389CD3CE AT ipass DOT net>
NNTP-Posting-Host: p24.tc4.newyo.ny.tiac.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Terry wrote in message <35B0ADBC DOT 389CD3CE AT ipass DOT net>...
|Martin Ambuhl wrote:
|>
|> John Meyer wrote in message <35b0151a DOT 9633555 AT news DOT rmi DOT net>...
|> |On Mon, 13 Jul 1998 22:28:54 -0700, Nate Eldredge <nate AT cartsys DOT com>
|> |wrote:
|> |
|> |>int a[3000][3000];
|> |
|> |
|> |Okay, but how do you make an array dynamic?
=========
My posting was absolutely wrong and should be ignored.  You have by now
seen correct answers. I have no idea what led me to write such drivel.
Perhaps working 15 hours before coming home to look at the newsgroup
contributed.
It is also true that this is answered in the comp.lang.c FAQ available
from ftp://rtfm.mit.edu/pub/usenet-by-group/comp.lang.c.  That FAQ is
not required reading here, as it is in comp.lang.c, but is still a
valuable resource.  It is a shield against the garbage (like my previous
post) that sometimes gets posted as "answers".

Martin Ambuhl (mambuhl AT tiac DOT net)
/* Newsgroup posts also e-mailed */
=========

|> ===========
|> #include <stdlib.h>
|> int main(void)
|> {
|>     int *a;
|>     if (!(a = malloc(9000000))) exit(EXIT_FAILURE);
|>     /* do stuff */
|>     free(a);
|>     return 0;
|> }
|>
|> Martin Ambuhl (mambuhl AT tiac DOT net)
|> /* Newsgroup posts also e-mailed */
|
|An alternative would be:
|
|#include <stdlib.h>
|int main(void)
|{
|    int **a;
|    int i;
|    a = (int **) malloc(3000*sizeof(int));
|    for(i=0;i<3000;i++)
|       a[i] = (int *) malloc(3000*sizeof(int);
|....
|
|   /* to free memory */
|   for(i=0;i<3000;i++)
|      free(a[i]);
|   free(a);
|}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019