Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Memory problems #27

Open
gigios opened this issue Sep 23, 2015 · 3 comments
Open

Memory problems #27

gigios opened this issue Sep 23, 2015 · 3 comments

Comments

@gigios
Copy link

gigios commented Sep 23, 2015

I'm trying to create a bridge application (external exe) to allow the acquisition of images from a 64bit application by a 32bit twain driver.
My first problem is that the acquired image is very big (7700x7200 pixels) and the size is about 166MB.
The problem is that during the full scan sequence the memory reach 700MB and more and I'm not able to save the image on disk (GDI+ raise a generic exception but I'm sure that it is related to the memory).
I don't know it there is a possibility to reduce this memory usage, what I have seen is that there are three allocation of 166MB: the acquisition made by the twain driver (DsImageTransfer), the render of the bitmap (RenderToBitmap), and the last is in my code, the convertion in a buffer to allow the send to the main application.

I have found a small workaround by moving the call of the event TransferImage (in the DataSourceManager) outside the block using (using (var renderer = new BitmapRenderer(hbitmap))) in this way the framework is able to reuse the memory allocated with the RenderToBitmap method.
The code changed is in the DataSourceManager.cs at line 235:

                    TransferImageEventArgs args;
                    using (var renderer = new BitmapRenderer(hbitmap))
                    {
                        args = new TransferImageEventArgs(renderer.RenderToBitmap(), pendingTransfer.Count != 0);
                    }
                    TransferImage(this, args);
                    if (!args.ContinueScanning)
                        break;

Any other suggestions are appreciated

@jeske
Copy link

jeske commented Jun 3, 2017

I just created a branch which adds an incremental MemoryXfer mode which transfers scan images in chunks instead of all at once. Currently it allocates a large bitmap to hold the whole image, but it could be adjusted to pass off partial bitmap buffers instead.

See: https://github.com/jeske/twaindotnet/tree/incremental_scanning

@gigios
Copy link
Author

gigios commented Jun 5, 2017

Ok! Thanks for the support.
I will test your version as soon as I have the opportunity to work again ont the project in question.

@Mark1975
Copy link

I just created a branch which adds an incremental MemoryXfer mode which transfers scan images in chunks instead of all at once. Currently it allocates a large bitmap to hold the whole image, but it could be adjusted to pass off partial bitmap buffers instead.

See: https://github.com/jeske/twaindotnet/tree/incremental_scanning

Hi Jeske, do you know why your pull request has not been merged with the main branch?
I need to implement scanning of 16 bit grayscale images; and a way to achieve that is by using Memory transfer; so your contribution would be a good starting point for me...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants