Solved

Win95 memory management ?

Posted on 1998-06-10
5
186 Views
Last Modified: 2013-12-03
I am programing Image processing software about 40000 lines.
but when program start, Win95 eats 100MB hard disk.

I use Win32 API functions.
This program requires the number of memory.
processing image size is about 1MB.
I often use static array varibales..
ex)
static int bmp[1024000];
what is problem ?....

thanks.
0
Comment
Question by:jhjeon
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1407501
100M is obviously too much.

If you use static variables like

static int bmp[1024000];

it will take up your memory until your program is unloaded.  So if you have 70-80 such variables, 100M is not unexpected.

Do you really want them to be static?  Normally for large buffer, it is better to allocate it in run time and free it immediately after you have used it.  For not so large memory, you can also declare them as local variables so that they will exist on the stack and whenever you exit the function, the memory will be freed.

0
 

Author Comment

by:jhjeon
ID: 1407502
I have another questions.

What is difference static declaration and run time alloction in WIN95 memory mangement
(really, all static variables is allocated when program start,
when static memory is allocated and free,
compare run time allocation to static allocation in
window memory management ..etc.).

and I want to know why 100MB memory is consumed ?,
total alloction memory is less than 100MB.

if you answer this questions, I will give you the points
0
 
LVL 7

Accepted Solution

by:
faster earned 100 total points
ID: 1407503
It is not really a matter of windows memory management, it is your program that claims it need 100M.

For static variables, the OS (in this case windows, but it is the same for all other OS) has to allocate memory and can not free it until your program terminates.  What the OS can do is to use virtual memory system when there is not enough physical memory.

So unless necessary, you should not use static variables.  Use automatic variables for normal variables in functions, sometimes you need to allocate memory at runtime, this is when you need a large memory or you don't know beforehand  how much you need.  For such memory, you decide when you should free it.  So in the entire lifetime of your application, you keep allocating memory and then free it, this way at any given point, the total memory usage is under control.

BTW, although you allcoate less than 100M, it will actaully use more than that figure because in the APIs and library fucntions, there are also memory allocations which you do not see.
0
 

Author Comment

by:jhjeon
ID: 1407504
I know that 100M is too much size.
but obviously, I don't know this problem.
anyway, thanks for your answer.
I will give you the points.
0
 
LVL 2

Expert Comment

by:xyzzer
ID: 8080925
I think this was quite an interesting discussion and I would like to invite you a similiar subject.

http://www.experts-exchange.com/Programming/Programming_Platforms/Win_Prog/Q_20536762.html
Which dynamic memory allocation method to use when?

--Filip
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 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