Buffers.html 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!DOCTYPE html> <HTML lang=en> <HEAD> <STYLE>
  2. body { background-color: #EEFFEE; font-size: 1.0rem; font-family: Arial; max-width: 60rem;
  3. color: #000000; margin: 0px;
  4. padding-left: 0px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; }
  5. H1 { padding-left: 10px; padding-right: 0px; padding-top: 10px; padding-bottom: 10px; font-size: 1.4rem; }
  6. H2 { padding-left: 10px; padding-right: 0px; padding-top: 10px; padding-bottom: 0px; font-size: 1.2rem; }
  7. blockquote {
  8. tab-size: 3rem;
  9. color: #88FF88; background: #000000;
  10. font-size: 0.95rem; font-family: monospace;
  11. padding-left: 5px; padding-right: 5px;
  12. padding-top: 5px; padding-bottom: 5px;
  13. }
  14. P { padding-left: 20px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; }
  15. IMG { padding-left: 0px; padding-right: 0px; padding-top: 2px; padding-bottom: 0px;
  16. max-width: 100%; }
  17. A { display: inline; border-radius: 4px;
  18. font-size: 1.0rem; font-family: Arial; color: #000044; text-decoration: none;
  19. padding-left: 4px; padding-right: 4px; padding-top: 4px; padding-bottom: 4px; }
  20. A:hover { color: #FFFF00; background: #000044; }
  21. A:active { color: #FFFFFF; background: #444444; }
  22. </STYLE> </HEAD> <BODY>
  23. <IMG SRC="Images/Title.png" ALT="Images/Title.png">
  24. <P>
  25. <A href="Manual.html">Back to main page</A>
  26. </P><P>
  27. </P><H1> Buffers</H1><P>Every file that is saved or loaded in the framework will pass through a Buffer.
  28. Buffers can not refer to each other in cycles and are automatically reference counted and deleted, so that you don't have to worry about memory leaks unless something holding a buffer creates a cycle of handles.
  29. They store a fixed size allocation of memory padded and aligned with DSR_MAXIMUM_ALIGNMENT bytes to work well with the largest SIMD vectors without false sharing of cache lines between threads.
  30. </P><P>
  31. </P><IMG SRC="Images/Border.png"><P>
  32. </P><H2> Construction</H2><P>
  33. </P><P>
  34. The default constructor creates an empty handle, so dsr::Buffer() can be treated as null and checked using the buffer_exists function.
  35. Returning an empty buffer handle is common when something went wrong with an operation.
  36. </P><P>
  37. To create a buffer that actually stores something, call buffer_create with the number of bytes to contain as the only argument.
  38. The memory always start initialized to zero, which prevents random bugs.
  39. </P><P>
  40. If you create a buffer of size zero, it will allocate the head but not the data.
  41. Trying to clone an empty buffer will just return the same handle without cloning, because empty buffers are immutable.
  42. </P><IMG SRC="Images/Border.png"><P>
  43. </P><H2> Read and write data access</H2><P>
  44. </P><P>
  45. Trying to get the pointer of a non-existing or zero length Buffer will safely return a null pointer, no matter if you use buffer_getSafeData<type>(buffer, "Buffer name") or buffer_dangerous_getUnsafeData(buffer).
  46. You access the data by getting a SafePointer, which can later be sliced into smaller parts.
  47. Sometimes you can't use the SafePointer because an operating system wants a regular pointer.
  48. </P><IMG SRC="Images/Border.png"><P>
  49. </P>
  50. </BODY> </HTML>