I\'m searching for a solution to solve the above described problem.
Here\'s my \"doesn\'t working code\". charsInCurrentBuffer returns always -1!
#d
When you read
from an O_DIRECT
fd, the "alignment of the user buffer and the file offset must all be multiples of the logical block size of the file system" (quoted from the open man page) on Linux. Other environments might have different constraints on this, and it's in fact filesystem dependent.
That's not going to be the case with new
generally (unless you get lucky).
You should consider using a posix_memalign
function if your platform has that, or simply allocate a larger buffer (BLOCK_SIZE + BUFSIZE) and use the block-size aligned part of it.
If you want to stick with new
, you're going to need to use some form of placement new combined with the above, but I'm not familiar enough with that to show how that would work.
For reference, see for example this thread on LKML, or the Notes section of the above-quoted man page.