2 Answers
2

It is copying the buffer to the new buffer (if not the same). The problem is that you are overwriting the buffer. "pval = val;" set your writing point to the first byte of the buffer, reaplacing any content. Try changing to "pval = val + loaded;".