Skip to content

Commit b350959

Browse files
committed
Add support for SAMD
1 parent d996a84 commit b350959

File tree

4 files changed

+110
-6
lines changed

4 files changed

+110
-6
lines changed

EfficientString/EfficientString.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void example10() {
100100

101101
// Construct "/api/outdoor_temp?key=0123456789"
102102
String path;
103-
path.reserve(64);
103+
path.reserve(63);
104104
path += "/api/";
105105
path += RESOURCE;
106106
path += "?key=";
@@ -114,7 +114,7 @@ void example11() {
114114

115115
// Construct "/api/outdoor_temp?key=0123456789"
116116
String path((char *)0);
117-
path.reserve(64);
117+
path.reserve(63);
118118
path += "/api/";
119119
path += RESOURCE;
120120
path += "?key=";

EfficientString/LoggingProxies.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ inline void strcpy_P(char *dst, const char *src) {
6161
}
6262
#endif
6363

64+
#ifndef strncpy_P
6465
inline void strncpy_P(char *dst, const char *src, size_t n) {
6566
::strncpy_P(dst, src, n);
6667
log(F("- strncpy_P(%p, %p, %u) - %u bytes"), dst, src, n,
6768
min(::strlen(src), n));
6869
}
70+
#endif
6971
} // namespace cpp4arduino

EfficientString/README.md

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Results
1919

2020
## On AVR
2121

22-
Here is the serial output of this program with the Arduino Core for AVR version 1.6.22:
22+
Here is output with the Arduino Core for AVR version 1.6.22:
2323

2424
```
2525
#1: Initialize from RAM
@@ -101,7 +101,7 @@ Here is the serial output of this program with the Arduino Core for AVR version
101101
- free(0x23c)
102102
103103
#11: Pass a null string to the constructor
104-
- malloc(65) -> 0x23c
104+
- malloc(64) -> 0x23c
105105
- strcpy(0x23c, 0x155) - 5 bytes
106106
- strcpy(0x241, 0x15b) - 12 bytes
107107
- strcpy(0x24d, 0x168) - 5 bytes
@@ -116,7 +116,7 @@ Here is the serial output of this program with the Arduino Core for AVR version
116116

117117
## On ESP8266
118118

119-
Here is the serial output of this program with the Arduino Core for ESP8266 version 2.4.2:
119+
Here is the output with the Arduino Core for ESP8266 version 2.4.2:
120120

121121
```
122122
#1: Initialize from RAM
@@ -209,4 +209,103 @@ Here is the serial output of this program with the Arduino Core for ESP8266 vers
209209
- malloc(33) -> 0x3ffef3fc
210210
- strcpy(0x3ffef3fc, 0x3ffe88c8) - 32 bytes
211211
- free(0x3ffef3fc)
212-
```
212+
```
213+
214+
## On SAMD
215+
216+
Here is the output with the Arduino Core for SAMD version 1.6.19:
217+
218+
```
219+
#1: Initialize from RAM
220+
- malloc(8) -> 0x20000a80
221+
- strcpy(0x20000a80, 0x8638) - 7 bytes
222+
- free(0x20000a80)
223+
224+
#2: Initialize from Flash
225+
- malloc(8) -> 0x20000a80
226+
- strcpy(0x20000a80, 0x8638) - 7 bytes
227+
- free(0x20000a80)
228+
229+
#3: toCharArray()
230+
- malloc(8) -> 0x20000a80
231+
- strcpy(0x20000a80, 0x8638) - 7 bytes
232+
- strncpy(0x20007fb8, 0x20000a80, 7) - 7 bytes
233+
- free(0x20000a80)
234+
235+
#4: c_str()
236+
- malloc(8) -> 0x20000a80
237+
- strcpy(0x20000a80, 0x8638) - 7 bytes
238+
- free(0x20000a80)
239+
240+
#5: Pass by value
241+
- malloc(8) -> 0x20000a80
242+
- strcpy(0x20000a80, 0x8638) - 7 bytes
243+
- malloc(8) -> 0x20000a90
244+
- strcpy(0x20000a90, 0x20000a80) - 7 bytes
245+
- free(0x20000a90)
246+
- free(0x20000a80)
247+
248+
#6: Pass by const reference
249+
- malloc(8) -> 0x20000a90
250+
- strcpy(0x20000a90, 0x8638) - 7 bytes
251+
- free(0x20000a90)
252+
253+
#7: Move instance
254+
- malloc(8) -> 0x20000a90
255+
- strcpy(0x20000a90, 0x8638) - 7 bytes
256+
- free(0x20000a90)
257+
- free(0)
258+
259+
#8: Append temporaries
260+
- malloc(6) -> 0x20000a90
261+
- strcpy(0x20000a90, 0x86cf) - 5 bytes
262+
- malloc(6) -> 0x20000a80
263+
- strcpy(0x20000a80, 0x20000a90) - 5 bytes
264+
- realloc(0x20000a80, 18) -> 0x20000aa0
265+
- strcpy(0x20000aa5, 0x86d5) - 12 bytes
266+
- realloc(0x20000aa0, 23) -> 0x20000ab8
267+
- strcpy(0x20000ac9, 0x86e2) - 5 bytes
268+
- realloc(0x20000ab8, 33) -> 0x20000ad8
269+
- strcpy(0x20000aee, 0x876b) - 10 bytes
270+
- malloc(33) -> 0x20000ab0
271+
- strcpy(0x20000ab0, 0x20000ad8) - 32 bytes
272+
- free(0x20000ad8)
273+
- free(0x20000a90)
274+
- free(0x20000ab0)
275+
276+
#9: Mutate instance
277+
- malloc(6) -> 0x20000af8
278+
- strcpy(0x20000af8, 0x86cf) - 5 bytes
279+
- realloc(0x20000af8, 18) -> 0x20000ad8
280+
- strcpy(0x20000add, 0x86d5) - 12 bytes
281+
- realloc(0x20000ad8, 23) -> 0x20000ad8
282+
- strcpy(0x20000ae9, 0x86e2) - 5 bytes
283+
- realloc(0x20000ad8, 33) -> 0x20000ab0
284+
- strcpy(0x20000ac6, 0x876b) - 10 bytes
285+
- free(0x20000ab0)
286+
287+
#10: Call reserve
288+
- malloc(1) -> 0x20000af8
289+
- strcpy(0x20000af8, 0x8b76) - 0 bytes
290+
- realloc(0x20000af8, 65) -> 0x20000ab0
291+
- strcpy(0x20000ab0, 0x86cf) - 5 bytes
292+
- strcpy(0x20000ab5, 0x86d5) - 12 bytes
293+
- strcpy(0x20000ac1, 0x86e2) - 5 bytes
294+
- strcpy(0x20000ac6, 0x876b) - 10 bytes
295+
- free(0x20000ab0)
296+
297+
#11: Pass a null string to the constructor
298+
- malloc(64) -> 0x20000ab8
299+
- strcpy(0x20000ab8, 0x86cf) - 5 bytes
300+
- strcpy(0x20000abd, 0x86d5) - 12 bytes
301+
- strcpy(0x20000ac9, 0x86e2) - 5 bytes
302+
- strcpy(0x20000ace, 0x876b) - 10 bytes
303+
- free(0x20000ab8)
304+
305+
#12: Concat at compile time
306+
- malloc(33) -> 0x20000ad8
307+
- strcpy(0x20000ad8, 0x8755) - 32 bytes
308+
- free(0x20000ad8)
309+
```
310+
311+
In #2 we can see that this board doesn't support Flash strings.

EfficientString/WString.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#include <Arduino.h>
2424
#include <avr/pgmspace.h>
25+
#if defined(ARDUINO_ARCH_SAMD)
26+
#include <avr/dtostrf.h>
27+
#endif
2528

2629
#include "LoggingProxies.h"
2730
#include "WString.h"

0 commit comments

Comments
 (0)