Re: Arrays of pointers to dcs

New Message Reply Date view Thread view Subject view Author view

Michael Jones (mtj++at++babar)
Thu, 15 Feb 1996 09:22:13 -0800


On Feb 15, 8:10am, chris wrote:
> Subject: Arrays of pointers to dcs
:
: 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?

Yes it is true, but not the way you mean. The issue is the difference
between a libpf object, an array of libpf objects, and an array of
pointers to libpf objects.

   pfDCS *dcs = new pfDCS;

is the only way to make a DCS. if you want an array of pointers to
DCS objects, that's easy:

   dcs = (pfDCS**)pfMalloc(sizeof(pfDCS*)*arraysize,pfGetSharedArena());
   if (dcs == NULL)
      bail_out_due_to_memory_exhaustion();
   for (int i = 0; i < arraysize; i++)
      dcs[i] = new pfDCS;

if you want an array of libpf objects (as opposed to an array of pointers
to them), then you're out of luck.

as an aside, n Java, the designers have met you half way. :-(

if you ask for a new THING, you get it. if you ask for an array of
new THINGs, you get the array of pointers but they're *not* filled
in. You then need the loop shown above in the C++ example.

if this is insufficient detail, check with Jim Helman, the performer
team's C++ api designer and expert.

michael

-- 

Be seeing you, Phone:415.933.1455 Fax:415.965.2658 M/S:8U-590 Michael T. Jones Silicon Graphics, Advanced Systems Division mtj++at++sgi.com 2011 N. Shoreline Blvd., Mtn. View, CA 94039-7311 "Du musst Amboss oder Hammer sein" -- Goethe


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.