Replies: 2 comments
-
Creates a huge list first.
|
Beta Was this translation helpful? Give feedback.
-
When you use 3000000 * [0], Python first creates a list of 3 million elements, each initialized to 0. range(3000000) doesn’t allocate all the memory for the numbers immediately; it’s a generator-like object that yields values one at a time. This method is more memory-efficient and avoids the problem of having to allocate a large temporary list in memory first. |
Beta Was this translation helpful? Give feedback.
-
I had some major problems allocating PSRAM on both ESP32-S3 WROOM N16R8 and Sparkfun Pro Micro RP2350. Both boards have 8M PSRAM.
If do this,
it fails to allocate memory. On ESP 32, I can't go beyond 1000000
However, using
a=array.array('h',range(3000000))
works. So using range is the right way. In fact, I can allocate 8M with array.array('h',4000000))
So why does the first method fail?
Another question. If PSRAM is enabled, is the internal SRAM used to store code or any heap? Seems internal SRAM would make things run faster.
Beta Was this translation helpful? Give feedback.
All reactions