> Paul Grenyer wrote:
> > Yes, but you're not exception safe, you'll get a leak. So what you
> > should really have is:
> > typedef std::auto_ptr< BITMAPINFO > BITMAPINFOPTR;
> BITMAPINFOPTR pBmi(
> > new BYTE [ sizeof (BITMAPINFO) + (sizeof (RGBQUAD)
> > * 8)) ]);
> > Then you'd be exception safe and you don't have to worry about
> > cleaning up either. However, std::auto_ptr is just plain
> wrong. You're
> > better off with boost::scoped or boost::shared_ptr.
>
> Aha yes exception safety. Indeed I think I'll use this approach (with
> shared_ptr of course). Thanks.

That should be shared_array, not shared_ptr.

And the way I would prefer to do it is:

BITMPINFO * pbmi = static_cast< BITMAPINFO * >  (operator new(
sizeof(BITMAPINFO) + (sizeof(RGBQUAD) * 8 ));

I use operator new( ) and operator delete( ) in such cases where I'm
allocating raw bytes of memory (not an object, etc.)

-------------
Ehsan Akhgari

Farda Technology (http://www.farda-tech.com/)

List Owner: [EMAIL PROTECTED]

[ Email: [EMAIL PROTECTED] ]
[ WWW: http://www.beginthread.com/Ehsan ]

Cold silence has a tendency to atrophy any sense of compassion...





Reply via email to