Solved

Win95 memory management ?

Posted on 1998-06-10
5
184 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

17 Experts available now in Live!

Get 1:1 Help Now