?
Solved

Win95 memory management ?

Posted on 1998-06-10
5
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

770 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