From 7083467876056623067
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,a30d08d161415a5f,start
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,a30d08d161415a5f,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1993-12-29 10:24:07 PST
Xref: gmd.de comp.std.c++:4917 comp.lang.c++:41567
Newsgroups: comp.std.c++,comp.lang.c++
Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!fnnews.fnal.gov!att-in!cbnewsi!sprocket
From: sprocket@cbnewsi.cb.att.com (dean.s.jones)
Subject: ANSI/ISO new[] and delete[]
Organization: AT&T
Date: Wed, 29 Dec 1993 18:17:40 GMT
Message-ID: <CIt6tM.GB1@cbnewsi.cb.att.com>
Lines: 74



	Could someone bring me up to date on the new[] and delete[] operators
proposed in ANSI/ISO C++. I have a copy of the ANSI/ISO Resolutions (Appendix
A for the ARM) from world.std.com. It states:

	r.12.5
	Two operators are introduced specifically to handle allocation and
	deallocation of arrays:

		void* operator new[](size_t);
		void operator delete[](void*);
		void operator delete[](void*, size_t);

	The use of the two forms of delete[] corresponds to their delete
	equivalents.

Since there is only one size_t parameter,  I assume it's value is defined as
N_ELEMENTS * sizeof(T).   I would have to derive the number of elements with
N_ELEMENTS = size / sizeof(T) if I needed that value.

	The ARM, Section 12.5 states that new & delete are inherited if they
have been defined for a class.

	To keep derived classes from using our per-class memory pools we use
the size parameter in the alternate form of delete described in 12.5 and the
size parameter from new to help us check these allocations:

void* T::operator new(size_t size)
{
	if(size != sizeof(T))
	{
		// a warning ???
		return ::new char[size];
	}
	else
	{
		return Some_Pool_Of_T.allocate();
	}
}

void T::operator delete(void *memp, size_t size)
{
	if(size != sizeof(T))
	{
		// a warning ???
		::delete [] memp;
	}
	else
	{
		Some_Pool_Of_T.free(memp);

	}
}

So...  These if these array allocators and deallocators are inherited and
not re-defined,  how can I protect myself from derived class allocations.
I could check to see if size is evenly divisible by sizeof(T),  but thats
no where near good enough.  Imagine:

class X : public T

where sizeof(X) == 2 * sizeof(T) or sizeof(X) is any multiple of sizeof(T)
or sizeof(T) == 1!!!.   Would this be an array of N class T's or N/2 class
X's ???  The same thing for the (alternate) delete operator.

Any help???

						Dean Jones
						dean@hos1cad.att.com






