Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!elroy.jpl.nasa.gov!swrinde!mips!spool.mu.edu!agate!agate!xjam From: xjam@cork.berkeley.edu (The Crossjammer) Newsgroups: comp.lang.c++ Subject: Getting info to new() Message-ID: Date: 20 Jun 91 00:15:11 GMT Sender: usenet@agate.berkeley.edu (USENET Administrator) Organization: University of California, Berserkeley Lines: 48 I might need some schooling about this, but I find it really inconvenient that there is no way to get the same information to an allocator (operator new) and an initializer (constructor) of an object. For example, I have to do the following to get allocation from a fixed pool of constants class FixnumCell { Fixtype x; FixnumCell(Fixtype q); void *operator new(int size, Fixtype q); }; inline FixnumCell::FixnumCell(Fixtype q) { if (// q in constant range) return; // This only works because I know what the allocator is // going to do in this case x = q; } void *FixnumCell::operator new(int size, Fixtype q) { if (// q in constant range) // find constant and return it } main () { FixnumCell *a = new (20) FixnumCell(20); // Should get preallocated constant FixnumCell *b = new (2ZILLION) FixnumCell(2ZILLION); // Need a new cell } This is also an "abuse" of what I perceive as the original use of overloading new, which was for object placement. Not that I know how to fix the problem, but it seems that allocation of space *is* part of an object's initialization, so why not let the constructor handle that as well. If there is a "correct" way to handle the problem then please let me know. Just blowing off some steam. -- They can't come on and play me in prime time, |Crossjammer ...... OUT! Cause I know the time, cause I'm gettin' mine. |xjam@yew.berkeley.edu I get on the mix late in the night... <-------------------PUBLIC ENEMY