• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - cabbott

1
Yes, Delphi 7.  Because even the latest version only supports 32-bit, I can't really justify upgrading.
2
Ok, looks like it is the Delphi memory manager causing fragmentation problems.
I have switched to FastMM and as if by magic, all the problems have gone away.

I would recommend FastMM to anyone thinking about serious memory usage in Delphi. It even has dialog where you can dynamically see all the memory allocations whilst your app is running.

It's available here http://sourceforge.net/projects/fastmm/.
3
Not using ResizeImage makes no difference, the problem still occurs.

I will do some more testing on another format over the weekend - need to convert 10,000 JPEG's to some other format to do this properly!

The errors indicate the app is out of memory, but only 110MB is allocated, well below the 2GB limit of a 32-bit app. So this suggests it is out of stack space.  I've tried increasing this but the problem still occurs at roughly the same place which would suggest it isn't this.

I've run the app through a leak checker and there are no leaks.

The only other possibility is memory fragmentation, causing the memory manager to eventually be unable to allocate one large chunk of memory. Not sure what can be done about this short of pre-allocating memory to load the images in.

I said that the problem doesn't occur outside of threads, this is not true, it does. It just takes a lot more images to create the problem - which again points to memory fragmentation.

I'll keep trying different methods of using the library and see if there is a better way of doing it. I am currently creating a new thread for each image, and within this thread a new set of calls to Vampyre.
This is obviously not the best way of doing it as this will clearly cause a lot of fragmentation. I think I need to move to 8 static threads with only 8 image objects.

Will let you know how I get on.
4
I have a fix, but you will probably want to track down the actual cause in the JPEG code and fix it properly.

LoadImageFromStream in Imaging.pas terminates prematurely if an exception occurs in Format.LoadFromStream(). It then leaves an entry in IArray with memory allocated that is never freed or allocated back to the callers Image property so the caller or FreeImage() can clear it.

Code snippet with amendments in bold:
try
    Result := Format.LoadFromStream(Stream, IArray, True);
    if Result and (Length(IArray) > 0) then
    begin
      Image := IArray[0];
      for I := 1 to Length(IArray) - 1 do
        FreeImage(IArray);
    end
    else begin
      Result := False;
    end;
except
      Result:=False;
      for I := 0 to Length(IArray) - 1 do
        FreeImage(IArray);
end;
5
Help & Questions / How thread safe is Vampyre?
8 October 2009, 15:51:35
I am seeing odd problems when running Vampyre across multiple threads.

On odd occasions it raises an exeption indicating either a Access Violation or Access Denied error reading/writing to memory. Eventually ending up with Out Of Memory errors.

Trying to debug it is a bit like the cat in the box scenario. The problem goes away if I try debugging because the threads have time to avoid memory conflicts.

Are there any areas within the following function calls that I might need to look out for or tweak?
TSingleImage.Create()
DetermineStreamFormat()
LoadFromStream()
ResizeImage()

I am only using the JPEG side of things at present

The Out Of Memory errors seem to stem from a memory leak when an exception occurs.
I'm not convinced all the allocated memory is being freed within Vampyre when an exception occurs. I am calling FreeImage() at the end of my processing regardless of the what happens during the above function calls.

If I run only one thread, or introduce delays everything is fine.
6
Thanks for responding.

By Bitmap I mean 24-bit decoded image (R8G8B8).

Yes, I started looking at JpegLib with a view to tweaking it.

This will certainly save me a huge memory and time overhead rending from JPEG to R8G8B8, then rescaling back to 32x32 R8G8B8. Why mess about with a 30MB image when a 3KB one will do!

If I get anywhere I will let you know, you could include it in a future build - I can't be the only one that wants to avoid wasted CPU time and memory!
7
I am running a threaded app that is loading JPG images and then rescaling them to 32x32.

Obviously this is resulting in each image being loaded, rendered to a Bitmap at full size, then resized back to 32x32.  All of which inhales memory like it's going out of fashion because I am running 8 threads!

Is there any way of loading a JPG image and rendering it directly to a specified size, thus avoiding the huge memory overhead rendering a full size Bitmap first?

I am using other image types as well, but lets concentrate on JPG to start with!

PS. Thanks for a very comprehensive imaging library.
SMF spam blocked by CleanTalk