Click here to Skip to main content
Click here to Skip to main content

Memory Allocation Tool

By , 20 Feb 2003
 

Sample Image - Alloc.jpg

Introduction

Sometimes it is very helpful to test your applications in extreme situations like low resources, full hard disk, or low memory conditions.

This tool covers just the last - memory. It allows you to allocate as much memory as might be available.

How to use

Run it. The dialog shows the basic memory allocation information like total/available/free memory, both physical and virtual. The view is equal to what you see in the Windows Taskmanager.

The slider has 3 tick marks - the start, the current memory limit and the end. The start means only that no memory at all is allocated. The end is the very end of the theoretical virtual memory which is usually at 2 GB. And the current memory limit is the amount of memory available.

Depending on the OS these values and their meaning may vary. If you have set your system to automatically manage virtual memory, then the current memory limit is variable and the tick will change as you allocate memory.

The minimum allocation size is 1 Megabyte; this is also the line size of the slider. If you press key up/down or left/right the allocation will increase/decrease in steps of 1 Mb. This is useful for fine-tuning available memory. The page size is 16 Mb (using page up/down keys). You can of course also just grab the slider with the mouse and drag it around; the current allocation is immediately shown.

Memory allocation errors or other problems are not shown. If memory can't be allocated, the slider won't update.

The checkbox "Allocate and use" shows different behaviors on different OS. Under Windows NT/2K/XP it will force Windows to actually keep the allocated memory block in memory. Otherwise, memory is allocated but not claimed in memory. If this is not checked you can allocate all available memory and you will not see any change in the physical memory allocation. Windows only claims this memory when you actually access it.

Information

It is written with WTL and STL under VC6 und runs under W2k and XP Pro (probably also under NT4 SP6). The project contains only a debug build and is only MBCS.

History

This is the promised update for non-Windows XP users. Now the application does no longer require the PSAPI.dll. Instead it emulates the GetPerformanceInfo() function by an internal function which returns almost the same information. The only differences are two values which I could not easily retrieve. These values are the "Commit Peak" and "System Cache" values. Probably you won't miss them anyway.

PS: Don't complain about memory leaks, they are your responsibility. :)

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Andreas Saurwein Franci Gonçalves
CEO Uniwares Ltda.
Brazil Brazil
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 1memberti_mo_n8 Mar '13 - 20:37 
Doesn't work at all.
GeneralVery GoodmemberVitaly Tomilov5 Sep '08 - 13:50 
Thank you for this nice article!
 
The best value it offered is by explaining how to get values of API GetPerformanceInfo on Windows 2000, and that's great!
 
I'm using this for my own open-source library
 
Regards,
Vitaly
 
Professional System Library on www.prosyslib.org

GeneralValues are missingmemberLokanatha Reddy30 Apr '07 - 23:36 
Hi,
When i run this tool under win-2k, it showing 'System Catche' as 0 and 'Peak' as 0. But my task manager showing actual values. How to get actual values?
 
Loka
Generalpf usagememberwelcomsmail2 Mar '07 - 4:36 
Can I get the value of "pf usage" like the task manager?
QuestionHow to make allocation sticky?memberthebigpixel2 Nov '06 - 10:14 
Great tool! Can anyone tell me how to make the memory allocation sticky when re-launching the executable?
GeneralIt doesn'nt work under W2Kmemberminouche15 Mar '04 - 6:39 
I 've tried your app under W2K SP4 and there is a problem with PdhAddCounter function, data value 0.(it work fine under my Xp).
GeneralAlmost...memberDarren Schroeder5 Feb '03 - 13:59 
Now all you need is the CPU Usage and PF Usage graphs and you'll have the Performance tab on task manager nailed! Great job. I always wondered where that information came from. I'd love to see an exact clone of Windows Task Manger.
 
Darren
GeneralRe: Almost...memberAndreas Saurwein5 Feb '03 - 23:26 
Its not that hard to clone the TaskManager. Getting the right data is the difficult part Smile | :)
And the processes tab is (partially) also covered by another article of mine.
Feel free to build the graphing controls and add all the other small gimmicks.
 

... you keep forgetting that sheep shagging is not a crime in Australia ...Paul Watson, The Lounge
Generalproblem of PSAPI.DLLmembersm7730 Jan '03 - 19:23 
this DLL included in xp version...is any way to run it under w2k (windows 2000)????????
how it can be solved............

GeneralRe: problem of PSAPI.DLLmemberAndreas Saurwein4 Feb '03 - 0:10 
I have updated the source code so it works now under W2k and XP equally and does not rely on the PSAPI.dll anymore.
The editors should have the download in place soon. Check for updates.
 

... you keep forgetting that sheep shagging is not a crime in Australia ...Paul Watson, The Lounge
Generalpsapi.dll and getperformanceinfomemberthorgrim20 Jan '03 - 22:49 
Hi,
 
I would like to try your work, but unfortunetly, I am not able to run the exe. I am getting some missing entry point in my psapi.dll -> getperformanceinfo could not be found.
 
I am working under 2k/2000. Where can I found the right .dll?
I have look on the web, but I find only old .dll for nt4.
 
Thanks
GeneralRe: psapi.dll and getperformanceinfomemberAndreas Saurwein20 Jan '03 - 23:16 
Duh. Oh my. WTF | :WTF:
My apologies for this. You are right. GetPerformanceInfo() is only available in the PSAPI.DLL included in WindowsXP.
I see a rewrite comming...
 

Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
GeneralRe: psapi.dll and getperformanceinfomemberAndreas Saurwein4 Feb '03 - 0:09 
I have updated the source code so it works now under W2k and XP equally and does not rely on the PSAPI.dll anymore.
The editors should have the download in place soon. Check for updates.
 

... you keep forgetting that sheep shagging is not a crime in Australia... Paul Watson, The Lounge
GeneralCompile Error fatal error RC1015: cannot open include file 'atlres.h'memberink19 Jan '03 - 23:29 
Thanks
 
Nature tells us how to ask
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'memberAndreas Saurwein20 Jan '03 - 2:43 
You should have read the article - this project is written using WTL, naturally you will need to have WTL installed.
Look at MSDN online for the download.
 

Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'memberNascott15 Nov '03 - 7:01 
now that I have the WTL files what do I do with them....
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'memberSaurweinAndreas15 Nov '03 - 12:29 
Nascott wrote:
now that I have the WTL files what do I do with them
 
Well, I've got some ideas what you could do with them, but probably it would be a good start to install the WTL package and then add the "wtl\include" folder to your include directories in VC.
Sigh | :sigh:
 

Finally moved to Brazil
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'sussAnonymous19 Feb '05 - 14:06 
Stick your high and mighty attitude elsewhere. Let me answer civilly...
1) Download WTL from Microsoft's MSDN
2) Extract it to "C:\Program Files\Microsoft Visual Studio\VC98\WTL" or wherever your MSVS is installed
3) Add "C:\Program Files\Microsoft Visual Studio\VC98\WTL\include" to the Additional Include Directories under the C/C++ and Resources tabs in your Project Settings dialog
 
Wink | ;)
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'membermercede23 Jul '08 - 19:49 
Just read the article and also ran into the same problem. Your suggestions work! thanks !
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'memberrcvf28 Oct '09 - 7:12 
Hello, i've included that folder on the project and I still get the same error.
what else can I do?
Thanks
GeneralRe: Compile Error fatal error RC1015: cannot open include file 'atlres.h'membersm7730 Jan '03 - 19:01 
don't know...

GeneralSorry, for the not working download. Its fixed.memberAndreas Saurwein18 Jan '03 - 5:07 
Thanks Nick, I really didnt try the download (it was already past 3am when I posted it and I just wante to go to bed Frown | :( )
 

 

Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
GeneralCoolmemberMarc Clifton18 Jan '03 - 3:17 
It was interesting to move the slider and have Windows pop up with a "virtual memory low" notification.
 
After looking at your code, I found this interesting in the MSDN:
 
When you allocate fixed memory, GlobalAlloc and LocalAlloc return a pointer that the calling process can immediately use to access the memory. When you allocate moveable memory, the return value is a handle. To get a pointer to a movable memory object, use the GlobalLock and LocalLock functions.

 
I didn't realize there was a difference in the value the GlobalAlloc returned (or maybe I just forgot).
 
Marc
 
Help! I'm an AI running around in someone's f*cked up universe simulator.
Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
Every line of code is a liability - Taka Muraoka

GeneralRe: CoolmemberAndreas Saurwein18 Jan '03 - 5:05 
Smile | :)
yeah, on the other hand the GlobalXxx functions are "outdated" and should be replaced with the HeapXxx or LocalXxx functions, but they are so handy Smile | :)
 
If you set your page file to system managed you can see your free diskspace shrink as you move the slider Cool | :cool:
 

Holy Sh*t! I'm speechless. (hey, that's a first) Marc Clifton, The Lounge
GeneralNice touch at the end...memberKant17 Jan '03 - 17:41 
Article title : Memory Allocation Tool
 
At the end "Dont complain about memory leaks, they are your responsability. Smile | :) "
 
Poke tongue | ;-P
 
I didn't vote your article, b'cos files are missing.

 

Kant
Sonork-100.28114

Don't Beer | [beer] and Drive.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 21 Feb 2003
Article Copyright 2003 by Andreas Saurwein Franci Gonçalves
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid