• WebAssembly学习



    WebAssembly简称wasm,是一个可移植、体积小、加载快并且兼容 Web 的全新格式。

    WebAssembly是一种用于在Web浏览器上直接运行C、C++等代码的技术,目前支持C、C++、Go、Rust、Asm.js等编译型语言。
    相比于JavaScript使用虚拟机执行,WebAssembly直接将C、C++、Go、Rust、Asm.js等代码编译成二进制由机器执行,这样执行的性能非常高。
    除了可以在Web上方便的执行C、C++、Go、Rust、Asm.js外,WebAssembly编译后的文件(.wasm)非常小,并且具有可移植性(二进制文件)。

    简单使用:

    1. 获取emsdk(也可以手动下载)
    git clone https://github.com/juj/emsdk.git
    
    1. 安装并激活最新版本
    cd emsdk
    ./emsdk install latest
    ./emsdk activate latest
    
    1. 将emsdk中的工具加入环境变量
    source ./emsdk_env.sh
    
    1. 编写hello.c vim hello.c
    #include <stdio.h>
    int main(int argc, char ** argv) {
      printf("Hello, world!
    ");
    }
    
    1. 编译成嵌入wasm的html
    emcc hello.c -o hello.html
    
    1. 启动HTTP服务
    emrun --no_browser --host localhost --port 8800 .
    
    1. 访问 http://localhost:8800/hello.html

    使用WebAssembly可以将C、C++、Go、Rust、Asm.js等语言的代码的函数,嵌入到浏览器中,使用Console或JS进行调用,同时C、C++、Go、Rust等代码也可以调研JS相关的方法。

    参考:
    https://www.cnblogs.com/pied/p/11819291.html
    https://www.wasm.com.cn/getting-started/developers-guide/
    https://zhuanlan.zhihu.com/p/158042212
    https://zhuanlan.zhihu.com/p/51335026

  • 相关阅读:
    day4
    day3
    day2
    day1
    spring-boot-note
    spring-boot-cli
    jquery ajax rest invoke
    spring-boot
    docker mysql
    jpa OneToMany
  • 原文地址:https://www.cnblogs.com/superhin/p/15248802.html
Copyright © 2020-2023  润新知