rtcSetDeviceMemoryMonitorFunction.3embree3 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. .TH "rtcSetDeviceMemoryMonitorFunction" "3" "" "" "Embree Ray Tracing Kernels 3"
  2. .SS NAME
  3. .IP
  4. .nf
  5. \f[C]
  6. rtcSetDeviceMemoryMonitorFunction\ \-\ registers\ a\ callback\ function
  7. \ \ to\ track\ memory\ consumption
  8. \f[]
  9. .fi
  10. .SS SYNOPSIS
  11. .IP
  12. .nf
  13. \f[C]
  14. #include\ <embree3/rtcore.h>
  15. typedef\ bool\ (*RTCMemoryMonitorFunction)(
  16. \ \ void*\ userPtr,
  17. \ \ ssize_t\ bytes,
  18. \ \ bool\ post
  19. );
  20. void\ rtcSetDeviceMemoryMonitorFunction(
  21. \ \ RTCDevice\ device,
  22. \ \ RTCMemoryMonitorFunction\ memoryMonitor,
  23. \ \ void*\ userPtr
  24. );
  25. \f[]
  26. .fi
  27. .SS DESCRIPTION
  28. .PP
  29. Using the \f[C]rtcSetDeviceMemoryMonitorFunction\f[] call, it is
  30. possible to register a callback function (\f[C]memoryMonitor\f[]
  31. argument) with payload (\f[C]userPtr\f[] argument) for a device
  32. (\f[C]device\f[] argument), which is called whenever internal memory is
  33. allocated or deallocated by objects of that device.
  34. Using this memory monitor callback mechanism, the application can track
  35. the memory consumption of an Embree device, and optionally terminate API
  36. calls that consume too much memory.
  37. .PP
  38. Only a single callback function can be registered per device, and
  39. further invocations overwrite the previously set callback function.
  40. Passing \f[C]NULL\f[] as function pointer disables the registered
  41. callback function.
  42. .PP
  43. Once registered, the Embree device will invoke the memory monitor
  44. callback function before or after it allocates or frees important memory
  45. blocks.
  46. The callback function gets passed the payload as specified at
  47. registration time (\f[C]userPtr\f[] argument), the number of bytes
  48. allocated or deallocated (\f[C]bytes\f[] argument), and whether the
  49. callback is invoked after the allocation or deallocation took place
  50. (\f[C]post\f[] argument).
  51. The callback function might get called from multiple threads
  52. concurrently.
  53. .PP
  54. The application can track the current memory usage of the Embree device
  55. by atomically accumulating the \f[C]bytes\f[] input parameter provided
  56. to the callback function.
  57. This parameter will be >0 for allocations and <0 for deallocations.
  58. .PP
  59. Embree will continue its operation normally when returning \f[C]true\f[]
  60. from the callback function.
  61. If \f[C]false\f[] is returned, Embree will cancel the current operation
  62. with the \f[C]RTC_ERROR_OUT_OF_MEMORY\f[] error code.
  63. Issuing multiple cancel requests from different threads is allowed.
  64. Canceling will only happen when the callback was called for allocations
  65. (bytes > 0), otherwise the cancel request will be ignored.
  66. .PP
  67. If a callback to cancel was invoked before the allocation happens
  68. (\f[C]post\ ==\ false\f[]), then the \f[C]bytes\f[] parameter should not
  69. be accumulated, as the allocation will never happen.
  70. If the callback to cancel was invoked after the allocation happened
  71. (\f[C]post\ ==\ true\f[]), then the \f[C]bytes\f[] parameter should be
  72. accumulated, as the allocation properly happened and a deallocation will
  73. later free that data block.
  74. .SS EXIT STATUS
  75. .PP
  76. On failure an error code is set that can be queried using
  77. \f[C]rtcGetDeviceError\f[].
  78. .SS SEE ALSO
  79. .PP
  80. [rtcNewDevice]