Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 liveuser 1
## Buffers
2
 
3
NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility.
4
 
5
 - <a href="#api_nan_new_buffer"><b><code>Nan::NewBuffer()</code></b></a>
6
 - <a href="#api_nan_copy_buffer"><b><code>Nan::CopyBuffer()</code></b></a>
7
 - <a href="#api_nan_free_callback"><b><code>Nan::FreeCallback()</code></b></a>
8
 
9
<a name="api_nan_new_buffer"></a>
10
### Nan::NewBuffer()
11
 
12
Allocate a new `node::Buffer` object with the specified size and optional data. Calls `node::Buffer::New()`.
13
 
14
Note that when creating a `Buffer` using `Nan::NewBuffer()` and an existing `char*`, it is assumed that the ownership of the pointer is being transferred to the new `Buffer` for management.
15
When a `node::Buffer` instance is garbage collected and a `FreeCallback` has not been specified, `data` will be disposed of via a call to `free()`.
16
You _must not_ free the memory space manually once you have created a `Buffer` in this way.
17
 
18
Signature:
19
 
20
```c++
21
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(uint32_t size)
22
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char* data, uint32_t size)
23
Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char *data,
24
                                           size_t length,
25
                                           Nan::FreeCallback callback,
26
                                           void *hint)
27
```
28
 
29
 
30
<a name="api_nan_copy_buffer"></a>
31
### Nan::CopyBuffer()
32
 
33
Similar to [`Nan::NewBuffer()`](#api_nan_new_buffer) except that an implicit memcpy will occur within Node. Calls `node::Buffer::Copy()`.
34
 
35
Management of the `char*` is left to the user, you should manually free the memory space if necessary as the new `Buffer` will have its own copy.
36
 
37
Signature:
38
 
39
```c++
40
Nan::MaybeLocal<v8::Object> Nan::CopyBuffer(const char *data, uint32_t size)
41
```
42
 
43
 
44
<a name="api_nan_free_callback"></a>
45
### Nan::FreeCallback()
46
 
47
A free callback that can be provided to [`Nan::NewBuffer()`](#api_nan_new_buffer).
48
The supplied callback will be invoked when the `Buffer` undergoes garbage collection.
49
 
50
Signature:
51
 
52
```c++
53
typedef void (*FreeCallback)(char *data, void *hint);
54
```