Modifications

Sauter à la navigation Sauter à la recherche
Ligne 36 : Ligne 36 :  
Et vous allez économiser 180 bytes/octets de notre merveilleuse SRAM!
 
Et vous allez économiser 180 bytes/octets de notre merveilleuse SRAM!
   −
== Réservez l'espace de vos Strings ==
+
== Réservez l'espace des chaines de caractères ==
   −
The Arduino string library allows you to reserve buffer space for a string with the '''fonction reserve()'''. The idea is you can prevent String from fragmenting the heap by using reserve(num) to pre-allocate memory for a String that grows.
+
Dans la libraire srting Arduino dévolue aux chaines de caractères, il existe la fonction '''fonction reserve()''' qui permet de réserver un espace mémoire (''buffer'' en anglais) pour une string.  
 +
 
 +
L'idée en de prévenir la fragmentation de la ''heap'' (le tas) en utilisant ''reserve(num)'' pour pré-allouer la mémoire d'un chaine de caractère destinée à grandir.
 +
 
 +
{{traduction}}
    
With the memory already allocated, String doesn't need to call realloc() if the string grows in length. In most usages, lots of other little String objects are used temporarily as you perform these operations, forcing the new string allocation to a new area of the heap and leaving a big hole where the previous one was (memory fragmentation). Usually all you need to do is use reserve() on any long-lived String objects that you know will be increasing in length as you process text.
 
With the memory already allocated, String doesn't need to call realloc() if the string grows in length. In most usages, lots of other little String objects are used temporarily as you perform these operations, forcing the new string allocation to a new area of the heap and leaving a big hole where the previous one was (memory fragmentation). Usually all you need to do is use reserve() on any long-lived String objects that you know will be increasing in length as you process text.
29 918

modifications

Menu de navigation