On Oct 2, 10:50=A0pm, "Chris M. Thomasson" <n...@[EMAIL PROTECTED]
> wrote:
> Please correct me if I am wrong, but it seems as if this particular
> allocator interface would "need" to know what type it was dealing with
in
> advance; correct?
Yes,
> In other words, it probably could not be used to overload
> global operator new/delete right?
Yes.
> Or, is `derived_t' dealing with internal
> allocator structures. Where am I going wrong here Dmitriy? You know, I
wa=
s
> thinking about creating something special for C++. But, I am a C
programm=
er,
> and felt the need to sup****t my language of choice. The cool thing about
=
C++
> is that you can do exactly what you did. Also, you can overload class
loc=
al
> delete operator and have it automatically return the size of the dynamic
> allocation be it single object or array. If the user allocated an array,
=
you
> simply divide this size of object size, and bam you have array size.
It's not always true. For example:
template<typename derived_t>
struct object_t
{
static void* operator new (size_t sz)
{
return malloc(sizeof(derived_t));
}
};
struct derived1 : object_t<derived1>
{
int x1;
};
struct derived2 : derived1
{
int x2;
};
derived2* d2 =3D new derived2 (); // CRASH! Allocate memory only for
derived1, derived2 will not fit into that memory
Dmitriy V'jukov


|