Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!helios!bcm!lib!thesis1.med.uth.tmc.edu From: jsorenso@thesis1.med.uth.tmc.edu (JEFFREY MARIUS SORENSON) Newsgroups: comp.sys.mac.programmer Subject: newD() function for ThinkC Message-ID: <5149@lib.tmc.edu> Date: 25 Jun 91 06:22:57 GMT Sender: usenet@lib.tmc.edu Distribution: usa Organization: University of Texas Medical School at Houston Lines: 42 Nntp-Posting-Host: thesis1.med.uth.tmc.edu Originator: jsorenso@thesis1.med.uth.tmc.edu I'm working on a project which involves lots of small "direct" (implemented as pointers) objects in ThinkC. As it stands, each time I create one of these objects I have to go through the sequence: size=sizeof(ClassName); newObject=(ClassName*)NewPtr(size); blessD(newObject, ClassName); To create (allocate) an indirect object, there is a function Symantec provided. void *new(void*); Now since I might have hundreds of different classes, I would like to write a functions, analogous to Symantec's new(), called newD() that allocates and blesses a direct object. This would seem feasible, so I created one with the same arguments as Symantec's new(). So Ideally I could write: newObject=newD(ClassName); However, since ClassName is passed as a pointer to void, I can't seem to get the size of the class from within my newD() function. void *newD(void *dummyClassName); since dummyClassName is just a pointer, sizeof(dummyClassName) is simply 4. You can't call sizeof(*dummyClassName), because that is an illegal use of the void type. Now I'm sure that this pointer to className must contain some sort of information about the size of the class. But how do I get to it? How does Symantec do it? (with their new() function, one passes the class name as a pointer to void). Has anyone been able to write a newD() function? If so, I would appreciate any tips. If it is for some reason impossible, I would like to know that too so I can give it up. I'm curious about why Symantec didn't provide a newD() function. I'm guessing that either they thought it would be easy enought for me to implement myself, or that there is something about using a pointer instead of a handle that makes it too difficult/impossible. Any clues? -- ------------------------------------------------------------------------------- jsorenso@thesis1.med.uth.tmc.edu | "No matter where you go, there you are" | -BB -------------------------------------------------------------------------------