Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Filehandling question =) — Gideros Forum

Filehandling question =)

katzekatze Member
edited April 2012 in General questions
Hey, if i do this 2 times:
Texture.new("gfx/test.png")
is then the graphic loaded 2 times?
or
is it loaded into memory allready when starting and this just retuns some stuff that is in some table with this name?
or
is it loaded into memory the first time, and in the second time then just the allready loaded and assigned with this filename stuff returned?
or
?

I saw alot of solutions for this so i just want to ask if i need to make me some ressource handling or if this is all handled allready and i dont need to take care for this.

Comments

  • You should create 2 new textures then. If they use the same texture memory, I don't know.
  • katzekatze Member
    yea, i mean if they share the memory then for the pixmap data =)
  • petecpetec Member
    Hi - I asked something similar and atilim's comment near the end of this thread says that Gideros reuses the texture if it's already on memory:

    http://www.giderosmobile.com/forum/discussion/comment/4008#Comment_4008
  • katzekatze Member
    edited April 2012
    ah, i should have been get deeper in the searching for this =) but thats perfect then, so i dont need to test if i loaded the texture allready or something =)
  • @Katze, even if you create multiple instances, I believe it should be one texture loaded in memory. However the texture variable might have a finite life depending on the scope of the variable.

    I prefer using Bitmap.new(Texture.new("file.png")) in one direct call, just in case you might want to use it too unless someone points out how this might not be such a good idea.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • atilimatilim Maintainer
    edited April 2012
    Hi @OZApps,

    It's safe and efficient to use Bitmap.new(Texture.new("file.png")) directly.
    local bitmap1 = Bitmap.new(Texture.new("file.png"))  --> loads and uses file.png
    local bitmap2 = Bitmap.new(Texture.new("file.png"))  --> reuses the data of file.png because it's already on memory. No extra texture memory is used here.
    And after bitmap1 and bitmap2 is GCed, the data of file.png is removed from memory.
    local bitmap1 = Bitmap.new(Texture.new("file.png"))  --> loads and uses file.png
    local bitmap2 = Bitmap.new(Texture.new("file.png"))  --> reuses file.png because it's already on memory
    bitmap1 = nil
    bitmap2 = nil
    collectgarbage() --> the data of file.png is removed from memory
    local bitmap3 = Bitmap.new(Texture.new("file.png"))  --> loads file.png again because it's not on memory

    Likes: avo

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.