Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Doubts about texture, bitmaps and memory consumption. — Gideros Forum

Doubts about texture, bitmaps and memory consumption.

kinrpgkinrpg Member
edited February 2020 in General questions
How are you guys?

Next, the question is ... if I load the texture in any variable:
local x = Texture.new("file.png")
And then do one:
stage: addChild(Bitmap.new(x))
I loaded this image into memory once and then displayed it on the screen ... Okay ... But what if I do for example one:
for i = 1, 10000 do
  stage:addChild(Bitmap.new(x))
end
Is the memory consumption 10 thousand times higher or will it only consume a single space because it is using the same texture 10 thousand times?

Tnx

Likes: MoKaLux

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • MoKaLuxMoKaLux Member
    edited February 2020
    nice to see you kinrpg. I am not sure about the answer but you can try profiling the code:
    https://wiki.giderosmobile.com/index.php/Profiling

    In gideros you just need to click this:

    It produces a nice html output :)
    Please share your results.
    profile.png
    253 x 378 - 11K
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • I don't know for sure (I neither checked Gidero's source code nor ran a profiler) but taken in account the quality Gideros, I'm pretty sure their developers made it so that it will always reference only one instace of texture.

    But it will be nice to see your profiling results.

    Regards.
    +1 -1 (+2 / -0 )Share on Facebook
  • The 2nd one - when you add the bitmap it points to the texture. They will all point to the same texture.

    Likes: MoKaLux, plicatibu

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+2 / -0 )Share on Facebook
  • The 2nd one - when you add the bitmap it points to the texture. They will all point to the same texture.

    So will all bitmaps displayed on the screen, in memory, occupy only one location?

    Cool...
  • rrraptorrrraptor Member
    edited February 2020
    app @ application
     
    local tex = {}
    for i = 1, 10 do tex[i] = Texture.new("obj.png", true) end
     
    function getMem(prefix)
    	collectgarbage()
    	collectgarbage()
    	print(prefix, 
    		("Texture memory: %f mb."):format(app:getTextureMemoryUsage() / 1024), 
    		("LUA memory: %f mb."):format(collectgarbage("count") / 1024)
    	)
    end
     
    getMem("Before")
    for i = 1, 200 do 
    	stage:addChild(Bitmap.new(tex[math.random(#tex)]))
    end
    getMem("After")
    I got this (image 96x96 px):
    Before Texture memory: 0.062500 mb. LUA memory: 0.123061 mb.
    After Texture memory: 0.062500 mb. LUA memory: 0.154635 mb.
    So, as you can see, texture memory is the same ;)
    +1 -1 (+3 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Gideros is even smarter: if you create multiple Texture objects with the same file, then texture data is also shared!
    +1 -1 (+5 / -0 )Share on Facebook
  • rrraptorrrraptor Member
    edited February 2020
    hgy29 said:

    Gideros is even smarter: if you create multiple Texture objects with the same file, then texture data is also shared!

    It realy is :) I've updated example above.

    But I prefer to store textures in local/global variables, cuz its a bit faster :D
    app @ application
    _TS @ |local __ts = os.clock() |
    TS_ @ |print("Elapsed time:", os.clock() - __ts, "s.")|
    N_TESTS @ 2000
     
     
    local ref = Texture.new("gfx/obj.png", true)
    print("Using reference")
    _TS
    for i = 1, N_TESTS do 
    	local btm = Bitmap.new(ref)
    end
    TS_
     
    print("Using contructor")
    _TS
    for i = 1, N_TESTS do 
    	local btm = Bitmap.new(Texture.new("gfx/obj.png", true))
    end
    TS_

    Likes: kinrpg

    +1 -1 (+1 / -0 )Share on Facebook
  • Sensational.

    I did a test with millions of sprites and particles and ran without lags etc ...

    I followed the tip of the colleague above also to put all textures in a gblobal variable, there it is easy to call from anywhere.

    Thank you.
    https://youtu.be/Q6z-3tG-WUg
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.