Hi

> Max wrote:
> > BITMAPINFO * pBmi = 0;
> > pBmi = (BITMAPINFO*) new BYTE [ sizeof (BITMAPINFO) + (sizeof 
(RGBQUAD) *
> > 8)) ];
> 
> Ah yes when you look at it that way... But to be honest this doesn't 
> look much better to me than the malloc() way (that is not to say that 
> this solution is not good, just that in these cases using new/delete 
> over malloc/free doesn't seem as compelling any more).

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.

Regards
Paul

Paul Grenyer
Email: [EMAIL PROTECTED]
Web: http://www.paulgrenyer.co.uk

Have you met Aeryn: http://www.paulgrenyer.co.uk/aeryn/?
Version 0.3.0 beta now available for download.




Reply via email to