Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Win95 memory management ?

Posted on 1998-06-10
5
Medium Priority
?
191 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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