In my Visual C ++ program, I use a custom operator newone that uses malloc()to allocate memory. My user operator newstores additional data in the first 4 bytes of memory and returns an offset pointer as the beginning of the block (program 32 bits):
void* operator new( size_t size )
{
size += sizeof( int );
int* result = static_cast<int*>( malloc( size ) );
if( result == 0 ) {
throw std::bad_alloc;
}
*result = ...
return result + 1;
}
Now, if the caller’s code wants to save a 64-bit ( __int64or double) variable , the block will not be correctly aligned for this.
What problems can occur in a 32-bit Windows program?
source
share