[GiNaC-list] hash tables and sets

Marko Riedel mriedel at lsi.upc.edu
Thu Oct 12 19:37:56 CEST 2006


Richard B. Kreckel writes:
 > Dear Marko,
 > 
 > Marko Riedel wrote:
 > 
 > >Someone hands me a chunk of memory through a void pointer, like so:
 > >
 > >    (void *)ptr.
 > >
 > >I want the memory pointed to by "ptr" to hold a newly initialized set
 > >of GiNaC expressions. How do I do this? How do I find out the number
 > >of bytes I will need? At some point in the future, someone will hand
 > >me that same pointer and I will want to free the set of expressions
 > >that it holds. Again, how do I do this?
 > >
 > 
 > Same as before. Don't let yourself be fooled by a funny long type name 
 > instead of a crisp "mystruct".
 > 
 > I suppose that should work (I haven't actually tested it):
 > 
 >     typedef std::set<GiNaC::ex, GiNaC::ex_is_less> myset;  // shorthand
 >     myset* inst;
 >     inst = (myset*)malloc(sizeof(myset));  // or get inst from elsewhere
 >     new(inst) myset;
 >     // do stuff to *inst here...
 >     inst->~myset();
 >     delete inst;
 > 

Okay, one last remark: the malloc should be matched up with a free,
right? Giving the sequence

   inst = (myset*)malloc(sizeof(myset));  // or get inst from elsewhere 
   new(inst) myset; 
   // do stuff to *inst here... 
   inst->~myset(); 
   free(inst);

Best regards, 

Marko

+-------------------------------------------------------------+
| Marko Riedel, EDV Neue Arbeit gGmbH, mriedel at lsi.upc.edu    |
| http://www.geocities.com/markoriedelde/index.html           |
+-------------------------------------------------------------+


More information about the GiNaC-list mailing list