初识

  1. package main.nio.netty.buf;
  2. import io.netty.buffer.ByteBuf;
  3. import io.netty.buffer.Unpooled;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.RandomAccessFile;
  7. import java.nio.MappedByteBuffer;
  8. import java.nio.channels.FileChannel;
  9. /**
  10. * @Description ByteBuf
  11. *
  12. * @Author Songxudong
  13. * @Date 2021/8/19 11:22 下午
  14. */
  15. public class ByteBufDemo {
  16. public static void main(String[] args) {
  17. // 直接缓冲区,不适用JVM堆内存,使用堆外内存
  18. // 使用Unsafe的setMemory等内存操作方法实现
  19. ByteBuf byteBuf = Unpooled.directBuffer(128);
  20. File file = new File("jw.txt");
  21. try {
  22. FileChannel fc = new RandomAccessFile(file, "rw").getChannel();
  23. MappedByteBuffer map = fc.map(FileChannel.MapMode.READ_WRITE, 0, file.length());
  24. map.put("jiangwang".getBytes());
  25. fc.position(file.length());
  26. map.clear();
  27. fc.write(map);
  28. } catch (IOException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32. }

简介

sdas

是的

  1. function myFunction(p1, p2) {
  2. return p1 * p2; // 该函数返回 p1 和 p2 的乘积
  3. }