java - Storing a lot of graphic data in memory (principle) -


i'm developing simple application 2d drawing ability use layers. tried different platforms (.net, java, qt...) , run same problem. can't understand how store graphic layers/images/bitmaps in memory efficiently, when canvas (each object stores graphic data) size big (like 3000x3000 pixels or so). suppose there's no other way store every layer image/bitmap object (or kind of color-data-array still consume alot of memory).

what have tried:

  • storing layer-objects directly in memory. fast access these objects if canvas size big , there many layer-objects, program crashes due memory usage overflow.
  • storing "active" layer-object in memory, while keeping other layers cached on hard drive. still need layer-objects accessed every time user draws stroke rebuild new final "visible" image. , when access cached layer-objects hard drive, it's slow, because need allocate of them in memory again 1 one , kill them after.
  • compress graphic data in layer-objects , store in memory. again, when have decompress graphic data 1 one every time need rebuild final visible image, it's slow too.

so correct way store alot of graphic objects? how popular software photoshop can handle many large layers , still work fast? know?

---- s o l u t o n ----

okay! evilruff, solved this. looks when read small needed slice of layer cached file, memory allocation proceeds faster when try allocate whole layer.

here's did:

  • on layer-object initialization, create new file on hard drive, filled zero-bytes (transparent pixels). way layer's graphic data not stored in memory.
  • when need bitmap/image slice layer-object, pass slice region coordinates. method in layer-object creates new empty bitmap/image , substitutes it's "bits" cached file's data, starting correct stride , position according region.
  • after manipulations bitmap/image done, pass layer-object's method updates cached file bitmap/image's new "bits". after flush bitmap/image memory.

works fast , there's 1 visible bitmap/image allocated in memory.

bad side: cached file every layer still takes hard drive's space. nowdays that's not critical when has large hard-drives.

well depends.. nature of drawings? vector based (like maps, diagrams ever) or work set of raster images put set of layers?


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -