From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001
From: Florian Merz <me@fiji-flo.de>
Date: Thu, 11 Feb 2021 12:36:08 +0100
Subject: unslug fr: move

---
 .../tools/memory/dom_allocation_example/index.html | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 files/fr/tools/memory/dom_allocation_example/index.html

(limited to 'files/fr/tools/memory/dom_allocation_example')

diff --git a/files/fr/tools/memory/dom_allocation_example/index.html b/files/fr/tools/memory/dom_allocation_example/index.html
new file mode 100644
index 0000000000..0f3a4b04d6
--- /dev/null
+++ b/files/fr/tools/memory/dom_allocation_example/index.html
@@ -0,0 +1,54 @@
+---
+title: Exemple d'allocation DOM
+slug: Outils/Memory/DOM_allocation_example
+translation_of: Tools/Memory/DOM_allocation_example
+---
+<div>{{ToolsSidebar}}</div><p>Cet article décrit une page web très simple qui sera utilisée pour illustrer certaines fonctionnalités de l'outil Mémoire.</p>
+
+<p>Il est possible de visiter le site à l'adresse : <a href="https://mdn.github.io/performance-scenarios/dom-allocs/alloc.html">https://mdn.github.io/performance-scenarios/dom-allocs/alloc.html</a>.</p>
+
+<p>Cette page contient simplement un script qui crée un grand nombre de noeuds DOM :</p>
+
+<pre class="brush: js">var toolbarButtonCount = 20;
+var toolbarCount = 200;
+
+function getRandomInt(min, max) {
+    return Math.floor(Math.random() * (max - min + 1)) + min;
+}
+
+function createToolbarButton() {
+  var toolbarButton = document.createElement("span");
+  toolbarButton.classList.add("toolbarbutton");
+  // empêche Spidermonkey de partager les instances
+  toolbarButton[getRandomInt(0,5000)] = "foo";
+  return toolbarButton;
+}
+
+function createToolbar() {
+  var toolbar = document.createElement("div");
+  // empêche Spidermonkey de partager les instances
+  toolbar[getRandomInt(0,5000)] = "foo";
+  for (var i = 0; i &lt; toolbarButtonCount; i++) {
+    var toolbarButton = createToolbarButton();
+    toolbar.appendChild(toolbarButton);
+  }
+  return toolbar;
+}
+
+function createToolbars() {
+  var container = document.getElementById("container");
+  for (var i = 0; i &lt; toolbarCount; i++) {
+    var toolbar = createToolbar();
+    container.appendChild(toolbar);
+  }
+}
+
+createToolbars();</pre>
+
+<p>Voici une représentation en pseudo-code de ce que fait ce code :</p>
+
+<pre>createToolbars()
+    -&gt; createToolbar() // appelé 200 fois. Crée un élément DIV à chaque fois
+       -&gt; createToolbarButton() // appelé 20 fois par <em>toolbar</em>, crée un élément SPAN à chaque fois</pre>
+
+<p>Ainsi, au total ce code crée 200 objets <code><a href="/fr/docs/Web/API/HTMLDivElement">HTMLDivElement</a></code>, et 4000 objets <code><a href="/fr/docs/Web/API/HTMLSpanElement">HTMLSpanElement</a></code>.</p>
-- 
cgit v1.2.3-54-g00ecf