Archived

This topic is now archived and is closed to further replies.

Julio

problems allocating a double buffer

Recommended Posts

I''m working with Borland C++ 3.0 and some VGA graphics stuff. For some reason I''m having trouble allocating memory for a double buffer. I don''t think I''m 64k short of memory, so I''m guessing there''s a problem in my code. here it is:
  
const int SCREEN_WIDTH=320;
const int SCREEN_HEIGHT=200;

unsigned char far *db=NULL;
unsigned int dbSize;
unsigned int dbHeight;

void InitDB()
{
	if((db=(unsigned char far *)_fmalloc(SCREEN_WIDTH*(SCREEN_HEIGHT+1)))==NULL)
	{
		cout << "Couldn''t initialize double buffer";
		return;
	}
	_fmemset(db,0,SCREEN_WIDTH*SCREEN_HEIGHT);
	dbHeight=SCREEN_HEIGHT;
	dbSize=SCREEN_HEIGHT*SCREEN_WIDTH/2;
}
  
what happens is the first error test fails. Everything compiles fine, it just errors out when I run it. any help would be appreciated. My Homepage How many Microsoft employees does it take to screw in a light bulb? None, they just declare drakness as a new standard.

Share this post


Link to post
Share on other sites
First of all, it should be SCREEN_WIDTH*SCREEN_HEIGHT, not SCREEN_WIDTH*(SCREEN_HEIGHT+1).

Besides that, your code seems OK. But this far pointer stuff looks very suspicious to me. Are you working in 16bit mode ? Why not replace _fmalloc() by simply malloc(), and drop all the far pointers.

BTW: You are not allocating a double buffer, but a single one (width*height), a double buffer would be width*height*2. Or did you mean an offscreen buffer ?

Share this post


Link to post
Share on other sites