Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!widener!brendan From: brendan@cs.widener.edu (Brendan Kehoe) Newsgroups: comp.lang.c Subject: re-sizing a 2-dim array Message-ID: Date: 16 May 91 18:14:55 GMT Organization: Widener CS Dept Lines: 36 I have a two-dimensional array, that I need to dynamically allocate at run-time. It's declared as: LINE **contents; I need to be able to read in any arbitrarily large list (n lines) into this array. I don't know how long the list is. (The example in the FAQ, of allocating n rows, can't be used in this case, since I've no idea how many rows could be in it to start with.) I was thinking of setting a limit of, say, 4096 or 8192 on it to begin with (declare it as LINE **contents = (LINE **) malloc (sizeof(LINE *) * 4096); for example). Then, when it read line 4097 (going outside the bounds of the current set), it'd bump the whole thing up to 8192 (or some increment), as so: LINE **new_contents = (LINE **) malloc (sizeof(LINE *) * 8192); and then do something like: bcopy((char *)contents, (char *)new_contents, sizeof(LINE *) * 4096); free(contents); contents = new_contents; to move the old set of pointers over to the new one. Is this a reasonable way to do it? Is there a better way? Thanks.. Brendan -- Brendan Kehoe - Widener Sun Network Manager - brendan@cs.widener.edu Widener University in Chester, PA A Bloody Sun-Dec War Zone "Visualize a dream; look for it in the present tense -- a greater calm than before. If you persist in your efforts, you can achieve...dream control."