memory.h.xml 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <chapter xml:id="memory.h">
  2. <title><tt>__vic/memory.h</tt></title>
  3. <p>Memory-related utilities.</p>
  4. <chapter xml:id="load_unaligned">
  5. <title><tt>load_unaligned()</tt></title>
  6. <code-block lang="C++"><![CDATA[
  7. template<class T>
  8. T load_unaligned(const void *p);
  9. ]]></code-block>
  10. <p>Load value from potentially unaligned address without causing bus error
  11. (<tt>SIGBUS</tt>).</p>
  12. <section><title>Example</title>
  13. <code-block lang="C++"><![CDATA[
  14. const void *p = ...;
  15. // int data = *static_cast<const int *>(p); // potential bus error
  16. int data = __vic::load_unaligned<int>(p);
  17. ]]></code-block>
  18. </section>
  19. </chapter>
  20. <chapter xml:id="store_unaligned">
  21. <title><tt>store_unaligned()</tt></title>
  22. <code-block lang="C++"><![CDATA[
  23. template<class T>
  24. void store_unaligned(void *p, T v);
  25. ]]></code-block>
  26. <p>Store value to potentially unaligned address without causing bus error
  27. (<tt>SIGBUS</tt>).</p>
  28. <section><title>Example</title>
  29. <code-block lang="C++"><![CDATA[
  30. void *p = ...;
  31. // *static_cast<int *>(p) = 123; // potential bus error
  32. __vic::store_unaligned(p, 123);
  33. ]]></code-block>
  34. </section>
  35. </chapter>
  36. </chapter>