Knowledge Flashcards
Garbage Collector
收集器实现:
引用计数收集器(Reference counting): 最早的也是最简单的垃圾回收实现方法,这种方法为占用物理空间的对象附加一个计数器,当有其他对象引用这个对象时计数器加一,反之引用解除时减一。这种算法会定期检查尚未被回收的对象的计数器,为零的话则回收其所占物理空间,因为此时的对象已经无法访问。这种方法无法回收循环引用的存储对象。(each object has a count of the number of references to it. Garbage is identified by having a reference count of zero)(在Python中,主要通过引用计数进行垃圾回收)
跟踪收集器 (Tracing): 近现代的垃圾回收实现方法,这种算法会定期遍历它管理的内存空间,从若干根储存对象开始查找与之相关的存储对象,然后标记其余的没有关联的存储对象,最后回收这些没有关联的存储对象占用的内存空间。( by tracing which objects are reachable by a chain of references from certain root objects, and considering the rest as garbage and collecting them; there are a large number of algorithms used in implementation)
Generics (Templates, Containers) 泛型 Java
泛型就是定义一种模板,例如ArrayList,然后在代码中为用到的类创建对应的ArrayList public class ArrayList { private T[] array; private int size; public void add(T e) {...} public void remove(int index) {...} public T get(int index) {...} } // 创建可以存储String的ArrayList: ArrayList strList = new ArrayList(); // 创建可以存储Float的ArrayList: ArrayList floatList = new ArrayList(); // 创建可以存储Person的ArrayList: ArrayList personList = new ArrayList();
WebAssembly
used by browser, no need to be parsed
faster, near native speed (compare to run Javascript which need to be parsed, compiled..) ,
can be translated from c, java,…
对于需要高计算量、对性能要求高的应用场景如图像/视频解码、图像处理、3D/WebVR/AR 等,优势非常明显
Interfaces (OOP)
Interface vs Abstract class
STEP 1: 创建Python Interface
- 继承抽象元类, 并将class中所有方法用@abstractmethod装饰
STEP 2: 创建正常类
- 继承该抽象类,implement所有抽象方法
使用abc模块可以很轻松的定义抽象基类:
from abc import ABCMeta, abstractmethod
class IStream(metaclass=ABCMeta): @abstractmethod def read(self, maxbytes=-1): pass
@abstractmethod def write(self, data): pass
Interface vs Abstract class Interface : ALL methods are abstract (=not implemented) Abstract class: if it contains one or more abstract methods.
Event-Driven Programming
- Event-driven programming is the dominant paradigm used in graphical user interfaces and other applications (e.g., JavaScript web applications) that are centered on performing certain actions in response to user input.
- main loop listens for events and triggers a callback function when one of those events is detected.
HTTP status codes
1xx Informational 2xx Success 200 OK 201 Created 204 No Content 3xx Redirection 304 Not Modified 4xx Client Error 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 409 Conflict 5xx Server Error 500 Internal Server Error
IP addresses, what is 127.0.0.1, ports and other basic networking notions
IPv4: 32 bits,10进制数 A类, 大型网络, public 0xxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx, 范围:0.0.0.0-127.255.255.255 Network.Node.Node.Node B类,中型网络,, public 10xxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx, 范围:128.0.0.0-191.255.255.255 Network.Network.Node.Node C类,小型网络, public 110xxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx, 范围:192.0.0.0-233.255.255.255 Network.Network.Network.Node D类组播:1110 private E类预留:1111 private
Reserved IP address:
192.168.0.0 - 192.168.0.0
Loopback / Localhost: 127.0.0.1 entire range available
IPv6: 128 bits, 16进制数
calling by reference vs calling by value, what is reference
- calling by reference: create a pointer that points to the SAME object
- calling by value: create a NEW object that have the value
heap & stack
操作系统方面
数据结构方面
操作系统方面
栈区(Stack):系统自动分配,速度较快,连续的内存区域,能从栈获得的空间较小(可能出现 overflow)
堆区(Heap):程序员分配释放 (如使用malloc),速度较慢,容易产生内存碎片,堆获得的空间比较灵活,也比较大
数据结构方面
栈(Stack):FILO 先进后出
堆(Heap):FIFO
Time related unix cmd
CRON
CRON: a time-based job scheduler in Unix-like computer operating systems
分时日月周
Comma ( , )列举: 1,3,4,7 * * * * echo hello world, 每小时的1、3、4、7分时,打印”hello world”
Dash( - ) 范围:1-6 * * * * echo hello world, 每小时的1到6分钟内,每分钟打印”hello world”
Asterisk( * ) 任何可能的值: 在“小时域”里的星号等于是“每一个小时”
Percent ( % ) “每”: *%10 * * * * echo hello world, 每10分钟打印一回”hello world”
Package management cmd
- homebrew
- yum
- apt
- Conan, vcpkg
- maven, gradle
homebrew: on Apple’s macOS
yum: Javascript
apt: on Debian, Ubuntu, and related Linux distributions.
Conan, vcpkg: c++
maven, gradle: java
Docker cmd
- docker create
- docker run
- docker rm
- docker build
docker create -it --name test daocloud.io/library/ubuntu # 创建一个容器命名为 test 使用镜像
docker run --name test daocloud.io/library/ubuntu # 创建并启动一个容器 名为 test 使用镜像 # run = create + start
docker rm [容器id] # 删除一个容器
docker build -t [image_name] [Dockerfile_path] # 根据Dockerfile 构建