G
Gernot Frisch
Hi,
I want to write a class that is returned by a debug version of new(),
that overloads an [] operator and can check the bounds at runtine,
know what I mean?
class AllocClass
{
public:
AllocClass(int sz, int bs)
{m_dat = malloc(sz); m_sz = sz; m_bs=bs;}
~AllocClass()
{if(m_dat) free(m_dat);}
void* operator[](int i)
{
if(i<0 || i>=m_sz)
__throw(42);
return (void*)m_dat+ i*m_bs;
}
char* m_dat;
int m_sz;
int m_bs; // size of a block;
};
void * __cdecl operator new(unsigned int size)
{
return (void*) AllocClass(size);
}
int main()
{
double* pD = new double[5];
pD[3] = 125.0; // call AllocClass.operator[]() ???
}
I somehow get the feeling I got such an error. On my PC implementation
everything works fine, on the ARM PocketPC, the graphics are messed
up - exaclty the same piece of code!
I want to write a class that is returned by a debug version of new(),
that overloads an [] operator and can check the bounds at runtine,
know what I mean?
class AllocClass
{
public:
AllocClass(int sz, int bs)
{m_dat = malloc(sz); m_sz = sz; m_bs=bs;}
~AllocClass()
{if(m_dat) free(m_dat);}
void* operator[](int i)
{
if(i<0 || i>=m_sz)
__throw(42);
return (void*)m_dat+ i*m_bs;
}
char* m_dat;
int m_sz;
int m_bs; // size of a block;
};
void * __cdecl operator new(unsigned int size)
{
return (void*) AllocClass(size);
}
int main()
{
double* pD = new double[5];
pD[3] = 125.0; // call AllocClass.operator[]() ???
}
I somehow get the feeling I got such an error. On my PC implementation
everything works fine, on the ARM PocketPC, the graphics are messed
up - exaclty the same piece of code!