{"id":6770,"date":"2025-06-12T14:56:46","date_gmt":"2025-06-12T12:56:46","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=6770"},"modified":"2025-06-12T15:21:56","modified_gmt":"2025-06-12T13:21:56","slug":"esp32-psram-on-steroids","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/","title":{"rendered":"HIMEM &#8211; ESP32 PSRAM on Steroids"},"content":{"rendered":"<p>Quite some time ago, I published some <a href=\"https:\/\/www.pschatzmann.ch\/home\/tag\/psram\/\">blogs about the ESP32 PSRAM. <\/a>I think it is about time to <strong>dig a litte deeper<\/strong> into the topic and look at how we can use the unadressable 4 MBytes.<\/p>\r\n\r\n<h3 class=\"wp-block-heading\">PSRAM and C++ STL<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">One thing that took me by <strong>surprise<\/strong> when I was testing with the actual ESP32 3.2.0 core, is that you just need to switch on the PSRAM in Arduino, and the <strong>C++ STL classes<\/strong> will automatically use the PSRAM. So if you need a bigger <strong>array<\/strong>: all you will need to do is to use a <strong>std::vector<\/strong>!<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">#include &lt;vector&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\">\/\/ create vector of int with 1000 entries with value 0 <\/span>\r\nstd::vector&lt;int&gt; my_vector(<span class=\"hljs-number\">1000<\/span>, <span class=\"hljs-number\">0<\/span>);\r\n\r\n<span class=\"hljs-comment\">\/\/ create empty vector where you can add entries with push_back() <\/span>\r\nstd::vector&lt;int&gt; my_vector1;\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The std::vector class is very powerful, and there are no reasons to use the old style C arrays any more and it is quite impressive that we can use all the STL container classes w\/o any additional code!<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">HIMEM<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The ESP32 can only address 4 MBytes of PSRAM directly. If you have 8MB, the addtional 4 MBytes can only be addressed with a combersome HIMEM paging API.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">To make the HIMEM very easy to use, I implemented a library that provides the following classes<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><strong>VectorHIMEM<\/strong> &#8211; a paged vector implementation<\/li>\r\n\r\n\r\n\r\n<li><strong>FileHIMEM<\/strong> &#8211; An API that let&#8217;s you access the HIMEM like a file<\/li>\r\n\r\n\r\n\r\n<li><strong>RingBufferStreamHIMEM<\/strong> &#8211; An Arduino Stream based RingBuffer<\/li>\r\n\r\n\r\n\r\n<li><strong>TypedRingBufferHIMEM<\/strong> &#8211; A RingBuffer for your custom types<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">To keep things consistent, I am also providing the corresponding classes for PSRAM.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Should you have the need for additinal container types, it should be easy to implement them on top of the VectorHIMEM class.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Performance Comparison<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">To minimize the number of allocations, you can call reserve() and indicate the number of entries. Here are the measured timings to insert 100000 int values into a Vector:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>PSRAM reserve 34 ms<\/li>\r\n\r\n\r\n\r\n<li>PSRAM 94 ms<\/li>\r\n\r\n\r\n\r\n<li>HIMEM reserve 150 ms<\/li>\r\n\r\n\r\n\r\n<li>HIMEM 539 ms<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Further information can be found in my <a href=\"https:\/\/github.com\/pschatzmann\/esp32-psram\">esp32-psram library<\/a>!<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Quite some time ago, I published some blogs about the ESP32 PSRAM. I think it is about time to dig a litte deeper into the topic and look at how we can use the unadressable 4 MBytes. PSRAM and C++ STL One thing that took me by surprise when I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20],"tags":[60],"class_list":["post-6770","post","type-post","status-publish","format-standard","hentry","category-arduino","tag-psram"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>HIMEM - ESP32 PSRAM on Steroids - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HIMEM - ESP32 PSRAM on Steroids - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"Quite some time ago, I published some blogs about the ESP32 PSRAM. I think it is about time to dig a litte deeper into the topic and look at how we can use the unadressable 4 MBytes. PSRAM and C++ STL One thing that took me by surprise when I [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-12T12:56:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-12T13:21:56+00:00\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"HIMEM &#8211; ESP32 PSRAM on Steroids\",\"datePublished\":\"2025-06-12T12:56:46+00:00\",\"dateModified\":\"2025-06-12T13:21:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/\"},\"wordCount\":308,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"keywords\":[\"PSRAM\"],\"articleSection\":[\"Arduino\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/\",\"name\":\"HIMEM - ESP32 PSRAM on Steroids - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"datePublished\":\"2025-06-12T12:56:46+00:00\",\"dateModified\":\"2025-06-12T13:21:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/06\\\/12\\\/esp32-psram-on-steroids\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HIMEM &#8211; ESP32 PSRAM on Steroids\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HIMEM - ESP32 PSRAM on Steroids - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/","og_locale":"en_US","og_type":"article","og_title":"HIMEM - ESP32 PSRAM on Steroids - Phil Schatzmann","og_description":"Quite some time ago, I published some blogs about the ESP32 PSRAM. I think it is about time to dig a litte deeper into the topic and look at how we can use the unadressable 4 MBytes. PSRAM and C++ STL One thing that took me by surprise when I [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/","og_site_name":"Phil Schatzmann","article_published_time":"2025-06-12T12:56:46+00:00","article_modified_time":"2025-06-12T13:21:56+00:00","author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"HIMEM &#8211; ESP32 PSRAM on Steroids","datePublished":"2025-06-12T12:56:46+00:00","dateModified":"2025-06-12T13:21:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/"},"wordCount":308,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"keywords":["PSRAM"],"articleSection":["Arduino"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/","url":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/","name":"HIMEM - ESP32 PSRAM on Steroids - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"datePublished":"2025-06-12T12:56:46+00:00","dateModified":"2025-06-12T13:21:56+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/06\/12\/esp32-psram-on-steroids\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"HIMEM &#8211; ESP32 PSRAM on Steroids"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=6770"}],"version-history":[{"count":11,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6770\/revisions"}],"predecessor-version":[{"id":6781,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6770\/revisions\/6781"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=6770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=6770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=6770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}