• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

visual c++ memory limitations?

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
kushcu
Asked:
kushcu
  • 3
  • 3
  • 2
  • +4
1 Solution
 
snoeglerCommented:
Can you post the values of 'rect.right' and 'rect.bottom' here? (Maybe also rect.left and rect.top)
0
 
jkrCommented:
And as you are posting that, what does 'GetLastError()' return after the call has failed?
0
 
jdrescherCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
MithanderCommented:
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
 
MDarlingCommented:
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
 
jonninCommented:
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
 
kushcuAuthor Commented:
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
 
jkrCommented:
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
 
kushcuAuthor Commented:
OK, I get the error. I've gotta to get some sleep, I called CreateCompatibleBitmap() in between SaveDC() - RestoreDC(). (for some other reason)
0
 
MDarlingCommented:
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
 
kushcuAuthor Commented:
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
 
MDarlingCommented:
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
 
jonninCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now