Solved

visual c++ memory limitations?

Posted on 2002-05-07
13
638 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

821 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