Sign in to follow this  
SeiferAlmasy

Memory problem

Recommended Posts

1. I use delphi 4. Delphi applications seem to have a problem or maybe just the way things have to be. I have an application that loads a jpeg image of size 500K. Once loaded it for some reason, stores it in memory as a bitmap. So the memory of the application is now about 10MB or more. Is there some way around this? 2. Also if I minimize my app then return it to the screen, the memory that was used is flushed??? The app returns to normal memory in task manager and the image is still there. 3. Is there any way to make my app memory as large as the images i am using. I.e. EXE size 3MB, image file external: 500K =mem of app in task M: 3.5MB?? I am a novice so any explanation of this will help.

Share this post


Link to post
Share on other sites
1. Jpeg images are compressed forms of images. So, if the compressed image has 500 kb, when uncompressed, ready for rendering, it could easily have 10 MB. The only way around this is to use a smaller jpeg with a lower compression and/or x/y size.

2. When you minimize the app it perhaps makes a copy of the rendered bitmap at the rendered (screen) size, which can be smaller than the entire image size. That would make up for the "difference" in size, since for lets say 400x300 pixels, the sistem would only need 480 kb of RAM.

3. Not really, because things need to be decompressed in order to be drawn on the screen. You could use a bitmap instead of the jpeg file (bitmap is uncompressed usually and therefore it can be rendered as such without the need for extra ram), but you would still need more memory than the exe size because the aplication itself will require it. Why do you exactly want to limit the memory requirement?
15 mega of occupied ram is not too much these days for PC/Windows.

You should check, though, whether or not you memory allocation are to be blamed
for the extra ram. I wouldn't be surprized if it was the jpeg implementation since Delphi 4 is rather old and I seem to remember that it had quite a few problems.

Share this post


Link to post
Share on other sites
JPG is a compressed file format - the image needs to be decompressed into a bitmap before it can be displayed.

Although it may be possible (I'm not sure that it is) to pass an uncompressed texture directly to the graphics card, it would be prohibitively slow.

Share this post


Link to post
Share on other sites
Quote:
Original post by SeiferAlmasy
1. I use delphi 4. Delphi applications seem to have a problem or maybe just the way things have to be.

I have an application that loads a jpeg image of size 500K. Once loaded it for some reason, stores it in memory as a bitmap. So the memory of the application is now about 10MB or more.

Is there some way around this?


I'm not using Delphi but assuming you're building a Windows app: Normally I use memory mapping feature to partially load the desired (large) file into memory (this useful technique is also be used in some other purposes such as cross process shared-memory). Typically the following functions are called:

1. Call CreateFileForMapping () to retrieve a handle for the desired file, at this phase there's no memory loaded.
2. Pass the retrieved handle to CreateFileMapping () function to have the OS prepared memory for the desired file.
3. Call MapViewOfFile () to actually load the file content into memory, you must specify the bottom and top offset of the accessing file. This function will be used multiple times to read the file from the beginning to the end without having to load the entire content to memory.
4. And lastly, don't forget to unload and close the file handle via these functions: UnmapViewOfFile () and CloseHandle ()

These functions details are quite complicated, at best you may refer to MSDN for more infos.

_Edit_: Guess I got you wrong at this question, just ignore it. And btw, all images you saw in Windows are bitmap, I'm not aware of any techniques that reduces the amount of memory for that extracted image.

Quote:
Original post by SeiferAlmasy
2. Also if I minimize my app then return it to the screen, the memory that was used is flushed??? The app returns to normal memory in task manager and the image is still there.


Not really, the memory usage (that *lost*) you see in Task Manager when your app is minimized is the amount of memory will be flushed if the system's memory is at a very low level.
In other hand, if you allocate 30 MB then when minimized, you see the memory usage reduced to 500 KB, that means these 500 KB is the minimum and critical amount of memory to keep the app running.
The remain (30 MB - 500 KB) will be flushed when remaining memory is low and will be reallocated when you restore the application.

Quote:
Original post by SeiferAlmasy
3. Is there any way to make my app memory as large as the images i am using. I.e. EXE size 3MB, image file external: 500K =mem of app in task M: 3.5MB??


Yeah maybe, if you put all the required data into the EXE file itself (some kind of resource). The OS will have to load the entire EXE file, which include the data.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this