GPHPER的菜地


  • 首页

  • 标签

  • 分类

  • 归档

Golang

发表于 2023-11-08 | 分类于 总结

GC 三色标记 https://zhuanlan.zhihu.com/p/334999060

内存管理

  • 小对象:小于32KB
    Tiny对象:1Byte 至 16 Byte 且不包含指针
    其他对象:16Byte 至 32KB
  • 大对象:大于等于32KB

中心

  • mcache mcentral mheap

流程

  • 计算对象所需内存大小size
  • 根据size到size class映射,计算出所需的size class
  • 根据size class和对象是否包含指针计算出span class
  • 获取该span class指向的span

mcache 中span class

  • 包含指针对象
  • 不包含指针对象的

mcentral span class

  • nonempty:这个链表里的span,所有span都至少有1个空闲的对象空间。这些span是mcache释放span时加入到该链表的。
  • empty:这个链表里的span,所有的span都不确定里面是否有空闲的对象空间。当一个span交给mcache的时候,就会加入到empty链表。

mheap的span管理

mheap里保存了两棵二叉排序树,按span的page数量进行排序:

  • free:free中保存的span是空闲并且非垃圾回收的span。
  • scav:scav中保存的是空闲并且已经垃圾回收的span。

汇编(五)

发表于 2022-10-03 | 分类于 汇编

跳转指令

offset 获取标号的偏移地址

jump 无条件跳转

  • jmp short 标号 范围为 -128 ~ 127 本质上跳转的是偏移地址,也就是改ip不改cs
1
2
3
4
5
6
7
8
9
10
11
12
13
assume cs:codesg

codesg segment
start: mov ax,0
jmp short s
add ax,1
s: inc ax

mov ax,4c00h
int 21h

codesg ends
end start
阅读全文 »

汇编(四)

发表于 2022-10-01 | 分类于 汇编

多段编程

  • 不分段时 [Debug查看]

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    assume cs:code

    code segment
    ;define word 的缩写
    dw 0123H,0456H,0789H,0abcH,0defH,0fedH,0cbaH,0987H
    start:mov bx,0
    mov ax,0
    mov cx,8
    s: add ax,cs:[bx] ;由于定义到cs段里面所以,内存的基地址位cs的地址
    add bx,2
    loop s

    mov ax,4c00H
    int 21H
    code ends
    end start ;指定指令入口
    阅读全文 »

汇编(三)

发表于 2022-09-13 | 分类于 汇编

1、伪指令

  • segment 段
    1
    2
    段名称  segment
    段名称 ends
    段名称也要标号
  • end 整个程序的结束
  • assume 假设某一 段寄存器 和程序中的某一用 segment…ends定义的段 相关联

2、程序返回

1
2
mov ax,4c00H
int 21H

示例

1
2
3
4
5
6
7
8
9
10
11
assume cs:abc

abc segment
mov ax,2
add ax,ax
add ax,ax
mov ax,4c00H
int 21H
abc ends

end

将 MASM中的程序和hello.asm 放到同一个目录下,打开DOSBOX,执行ML.EXE生成可执行文件 或者vscode安装 MASM/TASM 插件

阅读全文 »

汇编(一)

发表于 2022-09-10 | 分类于 汇编

CPU对存储器的读写

  • 存储单元的地址(地址信息)【通过地址总线】
  • 器件的选择,读或写命令 (控制信息)【通过控制总线】
  • 读或写的数据 (数据信息)【通过数据总线】

内存并不是一定指的是计算器的内存条的内存,显示器等硬件设备中也存在内存

RAM和ROM

  • RAM 随机可读写
  • ROM 只读,一般存在各个硬件的BIOS程序
阅读全文 »

汇编(二)

发表于 2022-09-10 | 分类于 汇编

1、物理地址计算

段地址 * 16 + 偏移地址

也可以描述成段地址左移4位加上偏移地址

2、内存地址描述

段地址是 2000H 偏移地址是 1F60

  • 描述1 数据存在内存 2000:1F60单元中
  • 描述2 数据存在内存的2000段中的1F60H单元中

3、段寄存器

  • CS寄存器【Code Segment 代码段寄存器】

    IP【Instruction Pointer】指令指针寄存器 即偏移地址

  • DS寄存器【Data Segment 数据段寄存器】

    使用 [0] 表示偏移量

  • SS寄存器【Stack Segment 堆栈段寄存器】

    SP 【Stack Pointer】存放栈顶的偏移地址

  • ES寄存器【Extend Segment 扩展段寄存器】
    阅读全文 »

Java基础(十) -- 线程

发表于 2022-06-20 | 分类于 Java

实现方式

继承Thread类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Method1 {
public static void main(String[] args) {
A a = new A();
a.start();
System.out.println("主线程输出"+Thread.currentThread().getName());
}
}

class A extends Thread{
@Override
public void run() {

int i = 0;
while (i < 10){
i++;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.println("子线程输出--"+Thread.currentThread().getName());
}
}
}
阅读全文 »

Java基础(七) -- 常用类

发表于 2022-05-28 | 分类于 Java

包装类

  • 针对八种基本数据类型相应的应用类型–包装类
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    public class Wrapper {
    public static void main(String[] args) {

    int i = 10;
    //手动装箱
    Integer iObj = new Integer(i);
    Integer iObj2 = Integer.valueOf(i);
    // 自动装箱
    Integer iObj3 = i;

    //手动拆箱
    int ii = iObj3.intValue();
    //自动拆箱
    int iii = iObj3;

    /*
    类方法使用
    */
    // 转为字符串
    String str1 = iObj.toString();
    // 字符串转int
    Integer si = Integer.parseInt("123");
    }
    }
  • Integer 类中使用自动或者 valueOf 转换时 -128 ~ 127 返回的是同一个对象
    阅读全文 »

Java基础(八) -- Math/Arrays/System/大数据/日期类

发表于 2022-05-28 | 分类于 Java

Math

Arrays

  • toString

    • 将数组转为字符串
    • 示例
      1
      2
      int[] arr = {1,2,3};
      System.out.println(Arrays.toString(arr));
  • sort

    • 排序数组
    • 示例
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
          public static void main(String[] args) {
      Integer[] arr = {1,2,3,4,5};
      Arrays.sort(arr, new Comparator() {
      @Override
      public int compare(Object o1, Object o2) {
      Integer i1 = (Integer) o1;
      Integer i2 = (Integer) o2;
      return i2 - i1;
      }
      });
      System.out.println(Arrays.toString(arr));
      }
      ```
      <!-- more -->
      * binarySearch
      + 二叉查找
      + 示例
      ```java
      Integer[] arr = {1,2,3,4,5};
      // 数组必须是有序的 小于0表示没找到
      System.out.println(Arrays.binarySearch(arr,4));
      ```

      * copyOf/fill/equals/asList
      + 复制/填充/比较/转为list
      + 示例
      ```java
      public static void main(String[] args) {
      Integer[] arr = {1,2,3,4,5};
      // 拷贝 length 个元素到arr2中
      Integer[] arr2 = Arrays.copyOf(arr,arr.length);
      System.out.println(Arrays.toString(arr2));

      Integer[] nums = {1,2,3};
      // 使用10替换原数组所有值
      Arrays.fill(nums,10);
      System.out.println(Arrays.toString(nums));

      Integer[] arr1 = {1,2,3,5,4};
      // 比较两个数组是否一致,完全一致包括顺序
      System.out.println(Arrays.equals(arr,arr1));

      // 将数组转为list
      List<Integer> list = Arrays.asList(arr);
      System.out.println(list);
      }

System

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void main(String[] args) {
// 获取当前毫秒时间戳
System.out.println(System.currentTimeMillis());

Integer[] arr = {1,2,3,4};
Integer[] arr2 = new Integer[3];
// 复制数组
System.arraycopy(arr,0,arr2,1,2);
System.out.println(Arrays.toString(arr2));

// 主动触发垃圾回收
System.gc();

// 退出
System.exit(0);
}

大数处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static void main(String[] args) {
BigInteger bigInteger = new BigInteger("32234234121231232234234212");
System.out.println(bigInteger);
// 加
bigInteger = bigInteger.add(new BigInteger("20"));
System.out.println(bigInteger);
// 减
bigInteger = bigInteger.subtract(new BigInteger("20"));
System.out.println(bigInteger);
// 乘
bigInteger = bigInteger.multiply(new BigInteger("20"));
System.out.println(bigInteger);
// 除
bigInteger = bigInteger.divide(new BigInteger("20"));
System.out.println(bigInteger);

// 大精度小数
BigDecimal bigDecimal = new BigDecimal("1231023.12312312312");
// 不指定精度操作时可能会出现无限循环所以抛出异常
// RoundingMode.CEILING 保留和分子相同的精度
bigDecimal = bigDecimal.divide(new BigDecimal("11.22"), RoundingMode.CEILING);
System.out.println(bigDecimal);
}

日期类

  • java.util.Date

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    package com.gphper.date;

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    public class DateClass {
    public static void main(String[] args) throws ParseException {
    Date date = new Date();
    System.out.println(date);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss E");
    System.out.println(dateFormat.format(date));

    //根据毫秒数计算时间
    Date date1 = new Date(953453453);
    System.out.println(date1);

    // 将字符串转为时间
    String s = "2023年06月01日 10:12:22 星期四";
    Date pdate = dateFormat.parse(s);
    System.out.println(pdate);
    }
    }
  • Calendar

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import java.util.Calendar;

    public class DateClass {
    public static void main(String[] args) {
    // 获取年月日信息需要单独获取
    Calendar instance = Calendar.getInstance();
    // 获取年份
    System.out.println(instance.get(Calendar.YEAR));
    // 获取月份
    System.out.println(instance.get(Calendar.MONTH) + 1);
    System.out.println(instance.get(Calendar.HOUR));
    System.out.println(instance.get(Calendar.HOUR_OF_DAY));
    }
    }
  • LocalDate / locaTime / LocalDateTime

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     import java.time.Instant;
    import java.time.LocalDateTime;
    import java.time.format.DateTimeFormatter;
    import java.util.Date;

    public class DateClass {
    public static void main(String[] args) {

    LocalDateTime now = LocalDateTime.now();
    System.out.println(now);
    System.out.println(now.getMinute());
    // 格式化时间格式
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 hh:mm:ss E");
    System.out.println(now.format(dateTimeFormatter));

    // 获取当前时间戳
    Instant now1 = Instant.now();
    System.out.println(now1);
    Date date = Date.from(now1);
    System.out.println(date);
    // Date 转 Instance
    now1 = date.toInstant();
    // 获取一天后的日期
    LocalDateTime m = now.plusDays(1);
    System.out.println(m.format(dateTimeFormatter));
    // 获取100天前
    LocalDateTime m1 = now.minusDays(100);
    System.out.println(m1.format(dateTimeFormatter));
    }
    }

Java基础(九) -- 集合

发表于 2022-05-28 | 分类于 Java
  • 集合分为两组
    • Collection 【单列集合】 包含 List 和 Set
    • Map 【双列集合】存放的 K-V 数据

Collection

  • List 和 Set

    阅读全文 »
<1234>

33 日志
6 分类
12 标签
© 2024 GPHPER
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4