blob: 885bb3dd6e0ca407121a3c57fee17b29fb8b3041 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
---
title: JS_NewRuntime
slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_NewRuntime
tags:
- JSAPI_Reference
- SpiderMonkey
translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_NewRuntime
---
<p>Initializes the JavaScript runtime.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval"><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JSRuntime" title="zh-CN/JSRuntime">JSRuntime</a> * <strong>JS_NewRuntime</strong>(uint32 maxbytes);
</pre>
<table class="fullwidth-table">
<tbody>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td><code>maxbytes</code></td>
<td><code>uint32</code></td>
<td>Maximum number of allocated bytes after which garbage collection is run.</td>
</tr>
</tbody>
</table>
<h2 id="Description" name="Description">Description</h2>
<p><code>JS_NewRuntime</code> initializes the JavaScript runtime environment. Call <code>JS_NewRuntime</code> before making any other API calls. <code>JS_NewRuntime</code> allocates memory for the <code>JSRuntime</code> and initializes certain internal runtime structures. <code>maxbytes</code> specifies the number of allocated bytes after which garbage collection is run.</p>
<p>Generally speaking, most applications need only one <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JSRuntime" title="zh-CN/JSRuntime">JSRuntime</a></code>. In a <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" title="zh-CN/JS_THREADSAFE">JS_THREADSAFE</a></code> build, each runtime is capable of handling multiple execution threads, using one <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JSRuntime" title="zh-CN/JSRuntime">JSContext</a></code> per thread, sharing the same <code>JSRuntime</code>. You only need multiple runtimes if your application requires completely separate JS engines that cannot share values, objects, and functions.</p>
<p>On success, <code>JS_NewRuntime</code> returns a pointer to the newly created runtime, which the caller must later destroy using <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_DestroyRuntime" title="zh-CN/JS_DestroyRuntime">JS_DestroyRuntime</a></code>. Otherwise it returns <code>NULL</code>.</p>
<h3 id="Notes" name="Notes">Notes</h3>
<p>Ordinarily, <code>JS_NewRuntime</code> should be the first JSAPI call in an application, and <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_DestroyRuntime" title="zh-CN/JS_DestroyRuntime">JS_DestroyRuntime</a></code> and <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_ShutDown" title="zh-CN/JS_ShutDown">JS_ShutDown</a></code> should be the last ones.</p>
<p>{{ LXRSearch("ident", "i", "JS_NewRuntime") }}</p>
|