Zatraceny Ccko

Pavel Brychta pavel.brychta na duhasys.eu
Úterý Říjen 31 13:16:32 CET 2017


Proč to funguje už tady vysvětleno bylo, jen je třeba ještě říct, že 
takto napsaná konstrukce je sice často používaná, ale typicky špatná 
zejména pro ESP8266 a to hned z více důvodů:

1. sčítání řetězců zbytečně zatěžuje stack/heap - je lepsí používat 
metodu .concat() objektu String (a pokud tuším zhruba, jak bude výsledný 
řetězec velký, tak si rezervuji prostor pomocí .reserve() )

2. takto zapsané řetězce zabírají cennou RAM, přičemž by mohly (a měly) 
být uloženy ve flash. Za tím účelem jsou vytvořeny odpovídající podpůrné 
makra - např. message.concat(F("URI:"));

Pokud vytvoříte nějaký větší kód do ESP, který by měl běžet trvale, tak 
tyhle dvě zásady ušetří spoustu trápení...

Pavel Brychta

Dne 31.10.2017 v 12:33 hwnews konference napsal(a):
> Hmmm, tak proc funguje tohle:
>
> String message = "File Not Found\n\n";
>   message += "URI: ";
>   message += server.uri();
>   message += "\nMethod: ";
>   message += (server.method() == HTTP_GET)?"GET":"POST";
>   message += "\nArguments: ";
>   message += server.args();
>   message += "\n";
>   for (uint8_t i=0; i<server.args(); i++){
>     message += " " + server.argName(i) + ": " + server.arg(i)+ "\n";
>   }
>   server.send(404, "text/plain", message);
>
>
>
> 2017-10-31 12:20 GMT+01:00 Jaromir Sukuba <jarin.hw na gmail.com 
> <mailto:jarin.hw na gmail.com>>:
>
>     " message += " " + rv_text+ "\n";"
>     takto sa v C-cku stringy nespajaju. Vlastne, v C-cku neexistuju
>     stringy, ale polia char-ov ukoncene nulami (a vlastne ani tie polia
>     neexistuju, len kus pamate na ktory ukazuje smernik). Tie sa daju
>     spajat trebars cez funckiu strcat, alebo mozno povedzme aj sprintf-om
>     (ma vacsie moznosti, ale tazkopadnejsia metoda).
>
>     2017-10-31 12:11 GMT+01:00 hwnews konference <hwnews na cncnet.info
>     <mailto:hwnews na cncnet.info>>:
>     > Zdravim,
>     >
>     > delam si ten palubni budik na lod s  e-ink displejem a ESP32.
>     Ohybam nejake
>     > knihovny, ktere jsou v examplech...na displej uz kreslim, web mi
>     take jede,
>     > ale zasekl jsem se na pro me nepochopitelne definici procedury:
>     >
>     > void DrawStringAt(int x, int y, const char* text, sFONT* font,
>     int colored);
>     >
>     > ja jsem tu deklaraci puvodne nezkoumal, protoze primo vlozeny
>     string jako
>     > parametr fungoval
>     >
>     > Kdyz jsem to ale chtel pouzit takto tak jsem si nabehnul:
>     >
>     > for (uint8_t i=0; i<server.args(); i++){
>     >     rv_text =  server.argName(i) + ": " + server.arg(i);
>     >     message += " " + rv_text+ "\n";
>     >     paint.DrawStringAt(0, 0, rv_text, &Font8, UNCOLORED);
>     >     epd.SetPartialWindow(paint.GetImage(), 0, 20+(i*12),
>     paint.GetWidth(),
>     > paint.GetHeight());
>     >   }
>     >
>     >
>     > void DrawStringAt(int x, int y, const char* text, sFONT* font,
>     int colored);
>     >         ^
>     > epdpaint.h:56:10: note:   no known conversion for argument 3
>     from 'String'
>     > to 'const char*'
>     >
>     > cela ta procedura je napsana takto:
>     >
>     > void Paint::DrawStringAt(int x, int y, const char* text, sFONT*
>     font, int
>     > colored) {
>     >     const char* p_text = text;
>     >     unsigned int counter = 0;
>     >     int refcolumn = x;
>     >
>     >     /* Send the string character by character on EPD */
>     >     while (*p_text != 0) {
>     >         /* Display one character on EPD */
>     >         DrawCharAt(refcolumn, y, *p_text, font, colored);
>     >         /* Decrement the column position by 16 */
>     >         refcolumn += font->Width;
>     >         /* Point on the next character */
>     >         p_text++;
>     >         counter++;
>     >     }
>     > }
>     >
>     > Jak by se to melo upravit abyto bylo koser?
>     >
>     > RV
>     >
>     > _______________________________________________
>     > HW-list mailing list  -  sponsored by www.HW.cz <http://www.HW.cz>
>     > Hw-list na list.hw.cz <mailto:Hw-list na list.hw.cz>
>     > http://list.hw.cz/mailman/listinfo/hw-list
>     <http://list.hw.cz/mailman/listinfo/hw-list>
>     >
>     _______________________________________________
>     HW-list mailing list  -  sponsored by www.HW.cz <http://www.HW.cz>
>     Hw-list na list.hw.cz <mailto:Hw-list na list.hw.cz>
>     http://list.hw.cz/mailman/listinfo/hw-list
>     <http://list.hw.cz/mailman/listinfo/hw-list>
>
>
>
>
> _______________________________________________
> HW-list mailing list  -  sponsored by www.HW.cz
> Hw-list na list.hw.cz
> http://list.hw.cz/mailman/listinfo/hw-list

------------- další část ---------------
HTML příloha byla odstraněna...
URL: <http://list.hw.cz/pipermail/hw-list/attachments/20171031/8ed94327/attachment.html>


Další informace o konferenci Hw-list