Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

buffers.md 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ## Buffers
  2. NAN's `node::Buffer` helpers exist as the API has changed across supported Node versions. Use these methods to ensure compatibility.
  3. - <a href="#api_nan_new_buffer"><b><code>Nan::NewBuffer()</code></b></a>
  4. - <a href="#api_nan_copy_buffer"><b><code>Nan::CopyBuffer()</code></b></a>
  5. - <a href="#api_nan_free_callback"><b><code>Nan::FreeCallback()</code></b></a>
  6. <a name="api_nan_new_buffer"></a>
  7. ### Nan::NewBuffer()
  8. Allocate a new `node::Buffer` object with the specified size and optional data. Calls `node::Buffer::New()`.
  9. 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.
  10. 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()`.
  11. You _must not_ free the memory space manually once you have created a `Buffer` in this way.
  12. Signature:
  13. ```c++
  14. Nan::MaybeLocal<v8::Object> Nan::NewBuffer(uint32_t size)
  15. Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char* data, uint32_t size)
  16. Nan::MaybeLocal<v8::Object> Nan::NewBuffer(char *data,
  17. size_t length,
  18. Nan::FreeCallback callback,
  19. void *hint)
  20. ```
  21. <a name="api_nan_copy_buffer"></a>
  22. ### Nan::CopyBuffer()
  23. Similar to [`Nan::NewBuffer()`](#api_nan_new_buffer) except that an implicit memcpy will occur within Node. Calls `node::Buffer::Copy()`.
  24. 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.
  25. Signature:
  26. ```c++
  27. Nan::MaybeLocal<v8::Object> Nan::CopyBuffer(const char *data, uint32_t size)
  28. ```
  29. <a name="api_nan_free_callback"></a>
  30. ### Nan::FreeCallback()
  31. A free callback that can be provided to [`Nan::NewBuffer()`](#api_nan_new_buffer).
  32. The supplied callback will be invoked when the `Buffer` undergoes garbage collection.
  33. Signature:
  34. ```c++
  35. typedef void (*FreeCallback)(char *data, void *hint);
  36. ```