Re: Arrays of pointers to dcs

New Message Reply Date view Thread view Subject view Author view

Nicolas Gauvin (nicolas++at++cae.ca)
Thu, 15 Feb 1996 13:25:27 -0500


>This was so easy in C.
>dcs = (pfDCS**)pfMalloc(sizeof(pfDCS*)*arraysize,pfGetSharedArena());
>Did the job just fine.

>I can't figure out how to do this in C++. The manual (Ch 14 p.486)
>says that pfDCS *dcs = new pfDCS;
>is the "only way" to create a libpf object. Is this true?

You can still do that. After pfMalloc your next step is to do:

for(int i=0; i<arraysize; i++)
  dcs[i] = new pfDCS;

You now have an array of pointers of pfDCS in C++;

And don't forget to pfDelete them when you are finished:

for(int i=0; i<arraysize; i++)
   pfDelete(dcs[i]);

pfFree(dcs);

PS: allocating an array is such a way is not the same as doing:
    dcs = new pfDCS[arraySize]; which is not safe at all.

-- 
     ___/     |       ___/ Nicolas Gauvin	   e-mail: nicolas++at++cae.ca
    /       / |      /     Software Developper	   voice: (514) 341-2000 x2275
   /       /  |     __/    CAE Electronics Ltd.    fax:   (514) 340-5496
  /       ___ |    /	   8585 Cote De Liesse, P.O. Box 1800
_____/  _/   _| _____/     Saint-Laurent, Quebec, Canada, H4L-4X4

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:24 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.