Question about image memory use

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
duck-and-wolf
Regular
Posts: 47
Joined: Thu Aug 29, 2019 6:20 pm
Completed: Head of the Class
Organization: Duck & Wolf
Contact:

Question about image memory use

#1 Post by duck-and-wolf » Sun Aug 30, 2020 6:29 pm

In these following examples, will Ren'Py load the foo.png image into memory only once, and then merely assign multiple 'pointers' at it, or will it load the same image into memory four times?

Code: Select all

image example_1a = "some_folder/foo.png"
image example_1b = "some_folder/foo.png"
image example_1c = "some_folder/foo.png"
image example_1d = "some_folder/foo.png"

Code: Select all

image example_2a = "some_folder/foo.png"
image example_2b = example_2a
image example_2c = example_2a
image example_2d = example_2a

Code: Select all

image example_3a = "some_folder/foo.png"
image example_3b = example_3a
image example_3c = example_3b
image example_3d = example_3c

duck-and-wolf
Regular
Posts: 47
Joined: Thu Aug 29, 2019 6:20 pm
Completed: Head of the Class
Organization: Duck & Wolf
Contact:

Re: Question about image memory use

#2 Post by duck-and-wolf » Fri Oct 30, 2020 12:03 pm

No one knows, huh?

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Question about image memory use

#3 Post by gas » Fri Oct 30, 2020 1:02 pm

Now, the thing is more complex than it does sound.
Renpy doesn't actually load anything in memory in advance at declaration phase. It does only on a prediction sense at runtime.
So, at declaration phase, nothing is stored in memory.
You can instantiate the same object 100 times or declare single 100 objects with the same picture parameter, the moment renpy need the image check if the picture is stored in memory and render it.

So, all such codes are equivalent. They create a reference to the IMAGE OBJECT, not the "picture".
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
_ticlock_
Veteran
Posts: 393
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Question about image memory use

#4 Post by _ticlock_ » Fri Oct 30, 2020 1:24 pm

I did a simple test, that probably answers your question. (it does not duplicate the image with the same name in your drive if you show them all)

Case 1:
(one image)
Image cache: 7.3% (21.8 MB)

Code: Select all

image example_1a = "p1.png"

screen test_screen():
    add "example_1a"
 
label start:
    call screen test_screen()
Case 2:
(4 equivalent images)
Image cache: 7.3% (21.8 MB)

Code: Select all

image example_1a = "p1.png"
image example_1b = "p1.png"
image example_1c = "p1.png"
image example_1d = "p1.png"

screen test_screen():
    add "example_1a"
    add "example_1b"
    add "example_1c"
    add "example_1d"
 
label start:
    call screen test_screen()
Case 3:
(control case - no images)
Image cache: 4.4% (13.2 MB)

Code: Select all

screen test_screen():
    pass
 
label start:
    call screen test_screen()
Case 4:
(4 identical images stored in the system with different names )
Image cache: 15.9% (47.6 MB)

Code: Select all

image example_1a = "p1.png"
image example_1b = "p2.png"
image example_1c = "p3.png"
image example_1d = "p4.png"

screen test_screen():
    add "example_1a"
    add "example_1b"
    add "example_1c"
    add "example_1d"
 
label start:
    call screen test_screen()

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Question about image memory use

#5 Post by gas » Fri Oct 30, 2020 1:46 pm

(I hate when people confirm what I've said with better examples XD)
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
_ticlock_
Veteran
Posts: 393
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Question about image memory use

#6 Post by _ticlock_ » Fri Oct 30, 2020 2:19 pm

gas, my intention was to illustrate what you've said since I already did the test.

User avatar
gas
Miko-Class Veteran
Posts: 838
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Question about image memory use

#7 Post by gas » Fri Oct 30, 2020 2:41 pm

_ticlock_ wrote:
Fri Oct 30, 2020 2:19 pm
gas, my intention was to illustrate what you've said since I already did the test.
You did extremely well, sometime to show the effects is better than explaining the cause.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3636
Joined: Mon Dec 14, 2015 5:05 am
Location: Your monitor
Contact:

Re: Question about image memory use

#8 Post by Imperf3kt » Fri Oct 30, 2020 8:10 pm

There's also the dev tools in the console (CTRL+D) that I believe will tell you more information about what is loaded into memory.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py

Post Reply

Who is online

Users browsing this forum: Google [Bot]