<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Add external SPI Flash Memory to Raspberry Pico - 5: pass STL containers as read-only parameters</title><link>/products/raspberry-pi/b/blog/posts/add-external-spi-flash-memory-to-raspberry-pico---5-pass-stl-containers-as-read-only-parameters</link><description>A projects to learn the SPI API of the RP2040 C SDK, and to use it to control an external Flash IC. In this post, I refine the m25 c++ class again. take care that an STL container is read-only when passing it to a member.





Pass...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Add external SPI Flash Memory to Raspberry Pico - 5: pass STL containers as read-only parameters</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/add-external-spi-flash-memory-to-raspberry-pico---5-pass-stl-containers-as-read-only-parameters</link><pubDate>Thu, 25 Jan 2024 17:29:26 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:dc3ac6aa-86c4-43e7-81af-2d7ea5b9babf</guid><dc:creator>andrethomas</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Hi, do you still have a download link for the read() and write() portions of the library? The last one I could find was 20221203 but that predates the read() thanks!&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25633&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Add external SPI Flash Memory to Raspberry Pico - 5: pass STL containers as read-only parameters</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/add-external-spi-flash-memory-to-raspberry-pico---5-pass-stl-containers-as-read-only-parameters</link><pubDate>Sun, 09 Apr 2023 11:54:47 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:dc3ac6aa-86c4-43e7-81af-2d7ea5b9babf</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;side note:&lt;br /&gt;In my write() method, I access the raw data buffer of the vector, via the [] operator:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:523018da-2379-49e2-82fa-2f7e21dd7f94:type=c_cpp&amp;text=std%3A%3Avector%3Cuint8_t%3E%20m25%3A%3Ardid%28%29%20%7B%0D%0A%20%20%20%20%2F%2F%20....%0D%0A%20%20%20%20spi_read_blocking%28spi%2C%200%2C%20%28%26v%5B0%5D%29%2C%20v.size%28%29%29%3B%20%2F%2F%20Manufacturer%20Identification%2C%20Device%20Identification%20%28Memory%20Type%20%7C%7C%20Memory%20Capacity%29%0D%0A%20%20%20%20%2F%2F%20...%0D%0A%7D]&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You could think that this may give my method the powers to modify the raw buffer. But there is protection:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;If the&amp;nbsp;&lt;/span&gt;vector&lt;span&gt;&amp;nbsp;object is const-qualified, the function returns a&amp;nbsp;&lt;/span&gt;&lt;tt&gt;const_reference&lt;/tt&gt;&lt;span&gt;. Otherwise, it returns a&amp;nbsp;&lt;/span&gt;&lt;tt&gt;reference&lt;/tt&gt;&lt;span&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In my code, I pass the vector as a const reference. So it&amp;#39;s const-qualified and the raw buffer can only be used in code that doesn&amp;#39;t alter it.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=25633&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>