# Printf gives memory access error and behaves weirdly

**URL:** <https://forums.developer.nvidia.com/t/printf-gives-memory-access-error-and-behaves-weirdly/224384>\
**Category:** OptiX\
**Created:** [August 18, 2022, 6:00pm UTC](https://forums.developer.nvidia.com/t/printf-gives-memory-access-error-and-behaves-weirdly/224384 "2022-08-18T18:00:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dhart](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/dhart/32/14043_2.png) [@dhart](https://forums.developer.nvidia.com/u/dhart)\
**Post date:** [August 18, 2022, 6:06pm UTC](https://forums.developer.nvidia.com/t/printf-gives-memory-access-error-and-behaves-weirdly/224384/2 "2022-08-18T18:06:19Z")

</div>

Hi @huyleq1989,

Do you have a lot of output? `printf` support relies on a CUDA buffering system, and it only has a small buffer, so easy to run out of buffer space which will truncate your output. See this thread [Size of printf buffer](https://forums.developer.nvidia.com/t/size-of-printf-buffer/160957)

It’s ideal to limit your printf output to a small amount, perhaps ideally by passing in the thread index to your kernel that you’d like debug, and only invoking printf when your thread index matches the parameter. Personally I like to wire up my thread index to a mouse click and/or a command line parameter to my application, to make it easy to dynamically set the pixel I’m interested in.

–  
David.

---

_[View the full topic](https://forums.developer.nvidia.com/t/printf-gives-memory-access-error-and-behaves-weirdly/224384)._
