{
  "source": "doc/api/smalloc.markdown",
  "modules": [
    {
      "textRaw": "Smalloc",
      "name": "smalloc",
      "stability": 1,
      "stabilityText": "Experimental",
      "classes": [
        {
          "textRaw": "Class: smalloc",
          "type": "class",
          "name": "smalloc",
          "desc": "<p>Buffers are backed by a simple allocator that only handles the assignation of\nexternal raw memory. Smalloc exposes that functionality.\n\n</p>\n",
          "methods": [
            {
              "textRaw": "smalloc.alloc(length[, receiver][, type])",
              "type": "method",
              "name": "alloc",
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`length` {Number} `<= smalloc.kMaxLength` ",
                      "name": "length",
                      "type": "Number",
                      "desc": "`<= smalloc.kMaxLength`"
                    },
                    {
                      "textRaw": "`receiver` {Object} Default: `new Object` ",
                      "name": "receiver",
                      "type": "Object",
                      "desc": "Default: `new Object`",
                      "optional": true
                    },
                    {
                      "textRaw": "`type` {Enum} Default: `Uint8` ",
                      "name": "type",
                      "type": "Enum",
                      "desc": "Default: `Uint8`",
                      "optional": true
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "length"
                    },
                    {
                      "name": "receiver",
                      "optional": true
                    },
                    {
                      "name": "type",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Returns <code>receiver</code> with allocated external array data. If no <code>receiver</code> is\npassed then a new Object will be created and returned.\n\n</p>\n<p>This can be used to create your own Buffer-like classes. No other properties are\nset, so the user will need to keep track of other necessary information (e.g.\n<code>length</code> of the allocation).\n\n</p>\n<pre><code>function SimpleData(n) {\n  this.length = n;\n  smalloc.alloc(this.length, this);\n}\n\nSimpleData.prototype = { /* ... */ };</code></pre>\n<p>It only checks if the <code>receiver</code> is an Object, and also not an Array. Because of\nthis it is possible to allocate external array data to more than a plain Object.\n\n</p>\n<pre><code>function allocMe() { }\nsmalloc.alloc(3, allocMe);\n\n// { [Function allocMe] &#39;0&#39;: 0, &#39;1&#39;: 0, &#39;2&#39;: 0 }</code></pre>\n<p>v8 does not support allocating external array data to an Array, and if passed\nwill throw.\n\n</p>\n<p>It&#39;s possible to specify the type of external array data you would like. All\npossible options are listed in <code>smalloc.Types</code>. Example usage:\n\n</p>\n<pre><code>var doubleArr = smalloc.alloc(3, smalloc.Types.Double);\n\nfor (var i = 0; i &lt; 3; i++)\n  doubleArr = i / 10;\n\n// { &#39;0&#39;: 0, &#39;1&#39;: 0.1, &#39;2&#39;: 0.2 }</code></pre>\n<p>It is not possible to freeze, seal and prevent extensions of objects with\nexternal data using <code>Object.freeze</code>, <code>Object.seal</code> and\n<code>Object.preventExtensions</code> respectively.\n\n</p>\n"
            },
            {
              "textRaw": "smalloc.dispose(obj)",
              "type": "method",
              "name": "dispose",
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`obj` Object ",
                      "name": "obj",
                      "desc": "Object"
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "obj"
                    }
                  ]
                }
              ],
              "desc": "<p>Free memory that has been allocated to an object via <code>smalloc.alloc</code>.\n\n</p>\n<pre><code>var a = {};\nsmalloc.alloc(3, a);\n\n// { &#39;0&#39;: 0, &#39;1&#39;: 0, &#39;2&#39;: 0 }\n\nsmalloc.dispose(a);\n\n// {}</code></pre>\n<p>This is useful to reduce strain on the garbage collector, but developers must be\ncareful. Cryptic errors may arise in applications that are difficult to trace.\n\n</p>\n<pre><code>var a = smalloc.alloc(4);\nvar b = smalloc.alloc(4);\n\n// perform this somewhere along the line\nsmalloc.dispose(b);\n\n// now trying to copy some data out\nsmalloc.copyOnto(b, 2, a, 0, 2);\n\n// now results in:\n// RangeError: copy_length &gt; source_length</code></pre>\n<p>After <code>dispose()</code> is called object still behaves as one with external data, for\nexample <code>smalloc.hasExternalData()</code> returns <code>true</code>.\n<code>dispose()</code> does not support Buffers, and will throw if passed.\n\n</p>\n"
            },
            {
              "textRaw": "smalloc.hasExternalData(obj)",
              "type": "method",
              "name": "hasExternalData",
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`obj` {Object} ",
                      "name": "obj",
                      "type": "Object"
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "obj"
                    }
                  ]
                }
              ],
              "desc": "<p>Returns <code>true</code> if the <code>obj</code> has externally allocated memory.\n\n</p>\n"
            }
          ],
          "modules": [
            {
              "textRaw": "smalloc.copyOnto(source, sourceStart, dest, destStart, copyLength);",
              "name": "smalloc.copyonto(source,_sourcestart,_dest,_deststart,_copylength);",
              "desc": "<p>Copy memory from one external array allocation to another. No arguments are\noptional, and any violation will throw.\n\n</p>\n<pre><code>var a = smalloc.alloc(4);\nvar b = smalloc.alloc(4);\n\nfor (var i = 0; i &lt; 4; i++) {\n  a[i] = i;\n  b[i] = i * 2;\n}\n\n// { &#39;0&#39;: 0, &#39;1&#39;: 1, &#39;2&#39;: 2, &#39;3&#39;: 3 }\n// { &#39;0&#39;: 0, &#39;1&#39;: 2, &#39;2&#39;: 4, &#39;3&#39;: 6 }\n\nsmalloc.copyOnto(b, 2, a, 0, 2);\n\n// { &#39;0&#39;: 4, &#39;1&#39;: 6, &#39;2&#39;: 2, &#39;3&#39;: 3 }</code></pre>\n<p><code>copyOnto</code> automatically detects the length of the allocation internally, so no\nneed to set any additional properties for this to work.\n\n</p>\n",
              "type": "module",
              "displayName": "smalloc.copyOnto(source, sourceStart, dest, destStart, copyLength);"
            }
          ],
          "properties": [
            {
              "textRaw": "smalloc.kMaxLength",
              "name": "kMaxLength",
              "desc": "<p>Size of maximum allocation. This is also applicable to Buffer creation.\n\n</p>\n"
            },
            {
              "textRaw": "smalloc.Types",
              "name": "Types",
              "desc": "<p>Enum of possible external array types. Contains:\n\n</p>\n<ul>\n<li><code>Int8</code></li>\n<li><code>Uint8</code></li>\n<li><code>Int16</code></li>\n<li><code>Uint16</code></li>\n<li><code>Int32</code></li>\n<li><code>Uint32</code></li>\n<li><code>Float</code></li>\n<li><code>Double</code></li>\n<li><code>Uint8Clamped</code></li>\n</ul>\n"
            }
          ]
        }
      ],
      "type": "module",
      "displayName": "Smalloc"
    }
  ]
}
