×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    34

    Loading too big images in a multithreaded setting - safe or not?

    Hello,

    I'd like to display images in my MIDP application. At the moment I'm using the standard Image.createImage(...) method to create images.

    Now, because of memory limitations, super large images (say, 1024x768) can't be loaded. The contract then is that Image.createImage will throw an OutOfMemoryError. This is easy to check in the application,

    try {
    img = Image.createImage(myInputStream);
    } catch( OutOfMemoryError e ) {
    displayError("too big");
    // catch other exceptions below
    }

    Now the question is: how safe is this code in a multithreaded setting?

    Option 1: it would be HORRID if the image loading thread would first allocate 99% of available memory, and just before it allocates that 1% of available memory (that would lead to OutOfMemoryError), ANOTHER thread tries allocating that very memory - in which case it's the another thread that will catch the OutOfMemoryError - and this only leads to pain (memory errors would have to be checked _everywhere_).

    Option 2: the Image.createImage would either allocate the memory for the image in a one big chunk (instead of little chunks) - OR throw the OutOfMemoryError "pre-emptively", i.e. first check the image size, and then compare the amount of free memory to it - no memory would actually be allocated unless there's enough of it. This option would be safe in multithreaded settings.

    Does anyone know wether MIDP subscribes to either option, or wether it's all device-specific?

    Thanks for your time,
    -- Mikko
    Last edited by uttumuttu; 2005-08-06 at 15:54.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×