Array of bitmaps firing Outofmemory even having sufficient memory

Asked

Viewed 163 times

2

Problem

I am having problem in my program that when the process reaches more than 1.5 GB of memory usage the process stops running and displayed an error of OutOfMemory.

In my process I’m reading a file .AVI and storing each frame in one Array de Bitmaps, so that I can run later on a player in a synchronized way.

Doubt

I don’t know if Windows limits a array a 1.5 GB and so it triggers a memory error even having enough space to continue. Someone has had this problem and knows some solution?

Additional information

There are 4 files in 30FPS sized 7MB each.
My computer is 64Bits, Windows 7, 8 GB de memória.

  • Video files, as far as I know, are compressed to the extreme. You’re not copying bitmaps, you’re converting enough compressed information from each frame to a format millions of times larger (I’m not exaggerating when I say millions). Surely there must be better ways to achieve your goal, if what you want is timing.

  • 1

    I suggest opening another question by saying what is your biggest problem (sync video and audio, maybe?). Maybe someone will get a solution otherwise.

  • @Renan obg for the quick response. So I’m doing it this way because I can better control the player. Ex: I can choose the exact point I want from the video. But this my question serves tb to other applications that use array that ends up getting mt large and passing the size of 1.5GB. I’ve had that kind of trouble on another show. I would like to know if you have any solution or way to solve this and increase the maximum array size.

  • I don’t understand these techniques, but I think you should use some kind of buffer (every player uses it). Loading all these frames in memory at once is very inefficient.

  • 2

    Storing ALL video data in memory may not be a good output because even if your program manages to address it there will be an underutilization of the memory. Why don’t you read the data in pieces (say, every 100 frames)? If you already know how to interpret the format (codec) of the video, "skip" to a given frame is simply to make a FileStream::Seek in the file for position i * s (where i = frame index from 0 to n and s = frame size in bytes).

  • 1

    @Luizvieira I’ll try to do it this way ! I think it will be the best way. Obg :)

  • Not at all. : ) Anyway, your question seems a little broad. From the comments you can infer that your problem is reading and playing the data from a video file, but the question seems to be about memory addressing limits in matrices in C#. If you’re going to keep this doubt, you might want to edit the question to at least include an example of succinct code (and easily playable).

  • 1

    Rsouza, if you want I can rephrase the question for you, considering what has already been discussed. And then you add more information if necessary.

  • Although the documentation is a bit confusing about this, an Outofmemoryexception occurs when there is no contiguous memory block available for the process with the desired dimension.

Show 4 more comments

2 answers

4


I don’t think your problem is a memory limitation, but a practical aspect of architecture. Environments that need to deal with content that cannot be carried and manipulated in a practical way in physical memory often use a partial load mechanism. One of them is the buffering.

In an implementation of buffer classical, the immediately following content (defined by a cargo window) of the reading cursor is loaded into memory, in an operation called read-Ahead. Optionally, and depending on the behavior required, the previous content is also sent to the buffer (read-Behind).

inserir a descrição da imagem aqui

As your reading cursor advances or recedes, content present in the opposite direction is discarded, and more content is prompted in the direction where the reading takes place.

The great advantage of this method is that you keep your memory usage on acceptable terms.

But there is a cost: If your reading cursor moves (Skip) for a position beyond the present in the buffer, you have to discard it and reload the new window (re-buffering).

If your reading cursor moves faster than the content load, you may cause a situation of underbuffer.

  • 1

    Mass response to assist with the concepts! : ) But, it would be nice if you quote the source of the image (I’m guessing it’s not yours because the text is in English).

  • 1

    Thank you, and I understand the concern - however the authorship of the image is mine, yes. The term 'current frame' would be 'Current frame' in English. The name of the software I use eh Gliffy Diagrams.

  • Dude, I didn’t even see "current" there. It was more. :)

  • 1

    No stress, @Luizvieira, the reason was noble ;)

  • 1

    That’s what I had in mind to try to solve this problem. @Onosendai . Obg :)

1

  • I’m using 4.0. I’ll take a look at this link. Obg :)

  • I saw that this would actually work if I used my 64bit platform application. Only I use 32bit Dlls so I can’t compile my application in 64bit but in 32bit. And This gcAllowVeryLargeObjects Feature doesn’t work. Would you have another parameter for 32bits? = X

  • The addressing space for 32-bit processes is limited in 2GB for applications which represents something like 1.2 to 1.4 available. The alternative is to change your program to load only what you have of available area, like a view window limited to free space.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.