# Having many PGraphics loaded lags

**URL:** <https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396>\
**Category:** Beginners\
**Created:** [March 21, 2023, 7:57pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396 "2023-03-21T19:57:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [March 21, 2023, 7:57pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/1 "2023-03-21T19:57:49Z")

</div>

Is it possible to prevent high gui usage with like 128 pgraphics?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [March 23, 2023, 6:48pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/2 "2023-03-23T18:48:56Z")

</div>

Just curious, are you using all 128 at one time?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [March 23, 2023, 7:28pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/3 "2023-03-23T19:28:46Z")

</div>

A simple question without a simple answer

It depends on many things including

- the size of the graphics (e.g. 256x256 requires ~64k, 1024x1024 requires ~1Mb)
- if they are preloaded in setup or loaded on demand, perhaps in draw
- if they are not loaded, when are they created e.g. inside draw()
- are the images modified during program execution, if so when are they updated and are the modifications CPU intensive (e.g. pixel level manipulation)

I think you need to provide some more info about the graphics and how they are used in your sketch.

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [March 23, 2023, 7:46pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/4 "2023-03-23T19:46:55Z")

</div>

no only one but i have an array with 128

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [March 23, 2023, 7:47pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/5 "2023-03-23T19:47:40Z")

</div>

the images are only modified for one. you can draw on one layer and not more at the same time.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [March 23, 2023, 8:28pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/6 "2023-03-23T20:28:07Z")

</div>

Any reason why you can’t load them as you need them, instead of loading all of them at one time?

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [March 23, 2023, 9:18pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/7 "2023-03-23T21:18:02Z")

</div>

Hi  
Additional for what @quark wrote  
Loading or creating big files depends on :  
CPU speed  
VGA card ram  
System ram  
Finely organization of how import/export /calling data

In void setup things happen once  
In void draw things without condition happen over and over

---

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [March 23, 2023, 11:42pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/8 "2023-03-23T23:42:09Z")

</div>

Store them as `PImage`s instead of `PGraphics` and have just one `PGraphics` as your active drawing surface. `image()` the active layer to it, then modify, and then copy it back to a `PImage` when done editing. `PImage` will take up less memory than `PGraphics`, but even then, 128 full screen images will require a lot of resources.

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [March 24, 2023, 1:12am UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/9 "2023-03-24T01:12:07Z")

</div>

That might actually work! Thanks!

---

<div class="post-metadata">

**Author:** ![Aryszin](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aryszin](https://discourse.processing.org/u/Aryszin)\
**Post date:** [March 24, 2023, 2:38pm UTC](https://discourse.processing.org/t/having-many-pgraphics-loaded-lags/41396/10 "2023-03-24T14:38:47Z")

</div>

cause a someone said they draw ob 500 layers/…
