Question

I was reading about how you can use the java nio library to take advantage of file transfer/buffering at the O/S level which is called 'zero copy'.

What are the differences in how you create/write to files then? Are there any drawbacks to using zero-copy?

Was it helpful?

Solution

zero copy means that your program will not transfer the data from the kernel space to the user space and so on. this is faster nice article can be found here: http://www.ibm.com/developerworks/library/j-zerocopy/

OTHER TIPS

Zero copy is a technique where the application is no longer the 'middleman' in transferring data from a disk to the socket. Applications that use zero copy request that the kernel copy the data directly from the disk file to the socket, without going through the application, which improves performance and reduces context switches.

It all depends on what the application will do with the data it reads from disks. If it is a web application serving a lot of static content by reading files and relaying them over sockets, then zero copy is the way to go in order to get better performance. However, if the application is using the data locally (either crunching it in some way and then writing it back, or displaying it locally without persisting it back), you would not use zero copy.

This IBM DeveloperWorks article about zero copy is a good read.

Other ways of file I/O in java are via the use of Stream classes based on the type of file you would want to read/write. This involves both buffered and unbuffered streams, although usually buffered streams promise better performance since they cause less I/O seek cycles and hence lesser context switches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top