Solved

visual c++ memory limitations?

Posted on 2002-05-07
13
632 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
Comment Utility
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
Comment Utility
And as you are posting that, what does 'GetLastError()' return after the call has failed?
0
 
LVL 1

Expert Comment

by:jdrescher
Comment Utility
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
 

Expert Comment

by:Mithander
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:kushcu
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now