Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / September 2007

Tip: Looking for answers? Try searching our database.

Memory Limit in Unmanged C++

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Leon Lambert - 06 Sep 2007 12:30 GMT
How do i get the amount of memory left for an application to allocate?
We have an application that badly needs redesign because the current
design can under certain circumstances run out of memory. Until we can
redesign it we need to add protections to prevent a crash. I would like
to determine when we are close to running out of memory and do a clean
abort of the current operation.

Using PSApi i can use GetProcessMemoryInfo to get the current
WorkingSetSize. I can't seem to find a number i can compare this against
to calculate approximate memory left. I know there is a hard 2 gig limit
but i think this can be lower based on pagefile sizes and such so would
like to make a Win32 call to get the limit.

Any help on how to figure out how much memory is left for a process to
use would be greatly appreciated.

Leon Lambert
Larry Smith - 06 Sep 2007 15:08 GMT
> How do i get the amount of memory left for an application to allocate? We
> have an application that badly needs redesign because the current design
[quoted text clipped - 11 lines]
> Any help on how to figure out how much memory is left for a process to use
> would be greatly appreciated.

http://msdn2.microsoft.com/en-us/library/aa366589.aspx
http://msdn2.microsoft.com/en-us/library/aa366781.aspx
Leon Lambert - 07 Sep 2007 11:10 GMT
>> How do i get the amount of memory left for an application to allocate? We
>> have an application that badly needs redesign because the current design
[quoted text clipped - 14 lines]
> http://msdn2.microsoft.com/en-us/library/aa366589.aspx
> http://msdn2.microsoft.com/en-us/library/aa366781.aspx 

Thanks this seems perfect.

Leon Lambert
Ben Voigt [C++ MVP] - 06 Sep 2007 19:16 GMT
> How do i get the amount of memory left for an application to allocate? We
> have an application that badly needs redesign because the current design
[quoted text clipped - 11 lines]
> Any help on how to figure out how much memory is left for a process to use
> would be greatly appreciated.

Realize that "bytes free" is nowhere near as important as the number and
sizes of free fragments on the heap.

If possible, can you allocate a decent-sized buffer for each operation, use
pieces of that buffer for the various temporary variables the operation
needs, and then free the whole thing when the operation finishes?  Then you
will decrease fragmentation a lot, and also there's only one allocation that
can fail.

> Leon Lambert
Leon Lambert - 07 Sep 2007 11:17 GMT
>> How do i get the amount of memory left for an application to allocate? We
>> have an application that badly needs redesign because the current design
[quoted text clipped - 22 lines]
>
>> Leon Lambert

I am not trying to get to be able to allocate the last bit of memory
available. I want a gross way of determining when a particular operation
is going crazy allocating memory. For example let say that 2 gig is the
maximum allocatable memory in the process. I would like to know when an
operation is getting within 300 or 400 megabytes of that maximum. This
leaves me plenty of space to do a clean abort. It would seem that link
that Larry provided will yield the information I need. Thanks for taking
the time to respond.

Leon Lambert

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.