Subject: Re: A *really* off question
To: Jeff Roberson <nomad@nop.aliensystems.com>
From: John A. Maier <johnam@mail.kemper.org>
List: tech-pkg
Date: 01/06/2000 11:32:25
On Wed, 05 Jan 2000, Jeff Roberson wrote:
> int nelem = 5;
> int nfree = 5;
> STUFF *stufp;
> 
> stfup = calloc(nelem, sizeof(STUFF));
> 
> Ten to add you do the following:
> if (nfree == 0) {
> 	nelem *= 2;
> 	stufp = realloc(stufp, sizeof(STUFF) * nelem);
> }

I found my C++ Pointers and Dynamic Memoery Management Book!  It was in my 6
year daughter's book trunk (no accounting for good taste :-). For some reason
she thought I gave it to her, so now I have a beutifully decorated Table of
Contents with "Haley Boock" and a heart at top in marker!

In C++ you must cast the allocation.

------  Code snip START ------
 int iCnt;
 STUFF *stuffit;
 stuffit =(STUFF *) malloc(sizeof(STUFF));  // This is the traditional C method
// stuff = new STUFF;  // here is C++'s answer to malloc

// Add Stuff
for(iCnt=0; iCnt<10, iCnt++)  {
	// in C++ there is no high level way of remallocing like with new
 	stuffit = (STUFF *) realloc(stuffit, (sizeof(STUFF) * (iCnt+1)) );
            // add stuff here.
 }
------  Code snip END ------

Thanks for all the help!

 -- 
John A. Maier
Kemper Military School and College
Director of MIS
Voice: 660-882-5623
Fax: 660-882-3778
Email: johnam@mail.kemper.org
Web: http://www.kemper.org