From -6975903400509553700 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,a30d08d161415a5f X-Google-Attributes: gidf78e5,public X-Google-Thread: 109fba,a30d08d161415a5f X-Google-Attributes: gid109fba,public X-Google-ArrivalTime: 1994-01-05 10:44:40 PST Xref: gmd.de comp.lang.c++:42029 comp.std.c++:4986 Path: gmd.de!xlink.net!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!rutgers!att-out!att-in!cbnewsi!sprocket From: sprocket@cbnewsi.cb.att.com (dean.s.jones) Newsgroups: comp.lang.c++,comp.std.c++ Subject: ANSI/ISO new[] and delete[] Message-ID: Date: 5 Jan 94 17:59:30 GMT Followup-To: comp.std.c++ Distribution: usa Organization: AT&T Lines: 73 This is my second posting, it seems the first one was lost somewhere in the queue... 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)) { return ::new char[size]; } else { return Some_Pool_Of_T.allocate(); } } void T::operator delete(void *memp, size_t size) { if(size != sizeof(T)) { ::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 Could it also be N * sizeof(T) + 4 ( to hold the number of bytes for delete ) ??