Solved

Win95 memory management ?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

10 Experts available now in Live!

Get 1:1 Help Now