nn_allocmsg.adoc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. nn_allocmsg(3)
  2. ==============
  3. NAME
  4. ----
  5. nn_allocmsg - allocate a message
  6. SYNOPSIS
  7. --------
  8. *#include <nanomsg/nn.h>*
  9. *void *nn_allocmsg (size_t 'size', int 'type');*
  10. DESCRIPTION
  11. -----------
  12. Allocate a message of the specified 'size' to be sent in zero-copy fashion.
  13. The content of the message is undefined after allocation and it should be filled
  14. in by the user. While <<nn_send#,nn_send(3)>> and <<nn_sendmsg#,nn_sendmsg(3)>> allow
  15. to send arbitrary buffers, buffers allocated using _nn_allocmsg()_ can be more
  16. efficient for large messages as they allow for using zero-copy techniques.
  17. 'type' parameter specifies type of allocation mechanism to use. Zero is the
  18. default one, however, individual transport mechanisms may define their
  19. own allocation mechanisms, such as allocating in shared memory or allocating
  20. a memory block pinned down to a physical memory address. Such allocation,
  21. when used with the transport that defines them, should be more efficient
  22. than the default allocation mechanism.
  23. RETURN VALUE
  24. ------------
  25. If the function succeeds pointer to newly allocated buffer is returned.
  26. Otherwise, NULL is returned and 'errno' is set to to one of the values
  27. defined below.
  28. ERRORS
  29. ------
  30. *EINVAL*::
  31. Supplied allocation 'type' is invalid.
  32. *ENOMEM*::
  33. Not enough memory to allocate the message.
  34. EXAMPLE
  35. -------
  36. ----
  37. void *buf = nn_allocmsg (12, 0);
  38. memcpy (buf, "Hello world!", 12);
  39. nn_send (s, &buf, NN_MSG, 0);
  40. ----
  41. SEE ALSO
  42. --------
  43. <<nn_freemsg#,nn_freemsg(3)>>
  44. <<nn_reallocmsg#,nn_reallocmsg(3)>>
  45. <<nn_send#,nn_send(3)>>
  46. <<nn_sendmsg#,nn_sendmsg(3)>>
  47. <<nanomsg#,nanomsg(7)>>
  48. AUTHORS
  49. -------
  50. link:mailto:sustrik@250bpm.com[Martin Sustrik]