Solved

visual c++ memory limitations?

Posted on 2002-05-07
13
639 Views
Last Modified: 2007-11-27
I'm trying to make a simple 2D game, and the program worked fine so far. I use full screen in 16 bits, with 4 different sprites. (and some 20 ships on screen) I checked RAM usage before, and the program uses 1 MB of memory (always).

Now I want to use double-buffering, and therefore I tried to create a back screen buffer (using win32 api only) with:
  hbmBuffer = CreateCompatibleBitmap(m_hdc, rect.right, rect.bottom);

This function call fails (returns a NULL pointer) due to unavailable memory. This call requires -at the most- 1.2 MB RAM, I have plenty more. I believe it's due to a setting problem related to Visual C++ 6. What should I change?
0
Comment
Question by:kushcu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +4
13 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 6993935
Can you post the values of 'rect.right' and 'rect.bottom' here? (Maybe also rect.left and rect.top)
0
 
LVL 86

Expert Comment

by:jkr
ID: 6993938
And as you are posting that, what does 'GetLastError()' return after the call has failed?
0
 
LVL 1

Expert Comment

by:jdrescher
ID: 6994040
Its not a RAM limitation. Visual C++ Will allow you to allocate as much ram as you have process address space (providing you have the physical ram or pagefile space). I have in one applciation allocated ~1.9GB of memory (in more than one chunk) with no problems.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Mithander
ID: 6994198
I'm not sure, but maybe it's trying to allocate video ram.  If that's the case it might explain why it's failing.

Mithander
0
 
LVL 3

Accepted Solution

by:
MDarling earned 100 total points
ID: 6994423
It's not trying to allocate video ram.

Either the rect is not properly defined or
there is something wrong with m_hdc.

How is m_hdc obtained?

How do you know it is failing due to "out of memory"?

Mike.
0
 
LVL 2

Expert Comment

by:jonnin
ID: 6994577
Might it be a stack error instead? this is small by default but can easily be increased in project settings...

also, memory allocations must be contigious, so if your ram is fragged, (Nt, xp, 2k) it can fail...  but would have to be badly fragged if you can't get a meg or 2.

0
 

Author Comment

by:kushcu
ID: 6994807
rect.left = 0, rect.top = 0, rect.bottom = 694, rect.right = 1016 (these are the maximum client area sizes defined for my monitor by Windows)

hdc is obtained by GetDC(hwnd) and normally works fine. (I draw 20 alienships, 1 humanship and some missiles on screen with it.)

I get the error number by:
  DWORD error = GetLastError();
which returns 8 as a result, defined as not enough memory in MSDN.

Since I'm using native Windows API, no video memory is involved.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6994817
I assume that it is not the actual memory that this error code refers to, but to GDI resources running out - are you releasing all GDI resources properly?
0
 

Author Comment

by:kushcu
ID: 6994820
OK, I get the error. I've gotta to get some sleep, I called CreateCompatibleBitmap() in between SaveDC() - RestoreDC(). (for some other reason)
0
 
LVL 3

Expert Comment

by:MDarling
ID: 6995121
Confused...

I get a B and I'm not sure I even answered a question...

Suspect he was calling GetDC() without ReleaseDC() somewhere and he was running low on GDI resources?
0
 

Author Comment

by:kushcu
ID: 6995226
you just made me check how I obtained the handle, and suddenly my code starting working. I gave a B because the answer wasn't a direct one. (Honestly, I didn't expect a direct answer. I post as small code fragments as possible to keep the experts interested.)
0
 
LVL 3

Expert Comment

by:MDarling
ID: 6995954
Just by checking? sounds a bit like quantum physics to me :-)

Well I'm glad it's working and I helped in some way.

Regards,
Mike.
0
 
LVL 2

Expert Comment

by:jonnin
ID: 6996282
you may have re-located the memory error. check again, or it may come back later...  it does not sound like you fixed it (even if it now works)
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question