Solved

When CEdit::Create returns 0

Posted on 1997-08-12
6
172 Views
Last Modified: 2013-11-19
I am developing a program with VC++ 4.0.  My development environment is on a Windows NT 4.0 system.  The program I am developing is being ported over to a Windows 3.11 (Windows For Workgroups) with Win32s installed.  That target machine is a 386 with 8 Megabytes of physical memory, and the virtual memory is set at approximately 16 Megabytes.

Here is the problem.  I am dynamically allocating objects that are derived from the CEdit class.  Eventually, the code calls the base class function CEdit::Create with the appropriate parameters.  On the 386 machine, about 89 to 95 objects get created OK, and then CEdit::Create returns a 0, indicating that the object could not be created.

Do any of your experts out there know under what conditions CEdit::Create will return a 0?  The Microsoft documentation does not provide much help. All I can find so far is that the return value from CEdit::Create is non-zero for success or 0 if it fails, but the documentation does not tell me why or what to look for.  I really could use some help on this
one.

Thanks.
0
Comment
Question by:jimn
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:mbhakta
Comment Utility
What version of Win32s are you on. There might be limitations for the number of objects being created on Win32s. Does the same application run properly if run on 32 bit version of windows ? Are you sure there are no memory leaks or exception caused during the process of creating other objects befor the CEdit based object ?
0
 
LVL 4

Accepted Solution

by:
davmarc earned 100 total points
Comment Utility
You probably got out of resources. Check the percantage of free USER memory heap at the moment of the failure, Win32s is only a little 32-bit and much 16-bit.

Davide Marcato.
0
 

Author Comment

by:jimn
Comment Utility
Thanks, davemarc.  But, before I grade your answer, I would like to ask you if you could tell me which resources I am out of.  After talking with my collegues, there are apparently two of them.  One is virtual memory.  When objects are allocated with the new operator, the memory returned is from the "heap", and it appears to be virtual memory.  However, when an object is a window, like CEdit, some physical memory is used.  I am using Win32s version 1.3.  To answer the comment from mbhakta, my application runs fine on Windows NT version 4.0.  So, apparently, Windows NT is doing something different when CEdit::Create is called by my application.  That system has 64 MBytes of physical memory, and something like 120 Mbytes of virtual memory.  So far, I haven't hit any memory limits on the NT yet. I am also using Visual C++ version 4.0.  Can you be a little more specific as to what you mean by "out of resources" please?  I will try your suggestion and try to determine the percentage of USER memory at the moment of failure.

Thanks.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:davmarc
Comment Utility
Creating CEdit objects requires both RAM (or virtual memory) and USER memory. You can test which one is exhausted sooner by reducing the amount of each one: the Stress utility coming with VC++ is fine for this.

In my opinion you get out of the USER heap: it is one segment of only 64KB in size, and 90 edit controls are quite a lot for it. Try to determine the percentage of free USER heap - its level will reveal this for sure.

Davide Marcato.
0
 

Author Comment

by:jimn
Comment Utility
Thanks, davemarc.  It turns out that the code I am working on did have a place where I could separate the allocation of the CEdit objects and the place where the CEdit object starts to draw the edit box.  By commenting out the place where the object is drawn, all of the object data fits just fine;  no out-of-memory errors (during the time between our emails I was experimenting on my own, and I haven't got around to doing a more detailed heap analysis yet).  So it looks like I have to keep this 64KB of USER heap in mind as I design a work-around to this problem.

Again, thanks for your help.

Jim

0
 
LVL 4

Expert Comment

by:davmarc
Comment Utility
Glad to help.

Davide Marcato
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

763 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

14 Experts available now in Live!

Get 1:1 Help Now