Jump to content
  • Advertisement

Archived

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

Julio

problems allocating a double buffer

This topic is 5767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!