You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/OS/CPU/CPU Cache.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,24 @@ Author Profile:
6
6
tags:
7
7
- OS
8
8
Creation Date: 2023-07-14T20:41:40+08:00
9
-
Last Date: 2024-01-11T23:21:39+08:00
9
+
Last Date: 2024-03-18T19:04:56+08:00
10
10
References:
11
11
---
12
12
## Abstract
13
13
---
14
-
- A *small-sized* type of volatile computer memory that provides *high-speed data access* to a [[CPU]]
14
+
- A **small-sized** type of volatile computer memory that provides **high-speed data access** to a [[CPU]]. **10-100 times faster** than accessing accessing data from [[Main Memory]]
15
15
16
+
## Cache Locality
17
+
---
18
+
![[cache_locality.gif]]
19
+
- Also known as **Locality of Reference**
20
+
-[[#Cache Line]] is transferred into [[CPU Cache]] when we obtain [[Instruction]] or [[Data]] from [[Main Memory]]
21
+
- If we are retrieving the same data or surrounding data. For the [[CPU]], instead of going to Main Memory to retrieve. It can obtain directly from the CPU Cache which is much faster (**10-100 times faster**)
22
+
</br>
23
+
24
+
- This contributes greatly to performance since [[Process (进程)]] usually only accesses a small portion of the [[Memory Address]] space within a small time interval
16
25
17
26
18
-
## Terminologies
19
-
---
20
27
### Cache Line
21
28
* Ranging from 32 to 128 [[Computer Data Representation#Byte]]
22
29
* When the CPU fetches data into the cache, it brings in entire cache lines rather than individual bytes
@@ -29,10 +36,3 @@ References:
29
36
- When the [[CPU]] requests data that is not found in the [[CPU Cache]]
30
37
- It requires fetching the data from the slower [[Main Memory]], incurring a higher access time compared to a [[#Cache Hit]]
31
38
32
-
### Cache Locality
33
-
- Also known as *Locality of Reference*
34
-
-[[#Cache Line]] is transferred into [[CPU Cache]] when we obtain [[Instruction]] or [[Data]] from [[Main Memory]]
35
-
- If we are retrieving the same data or surrounding data. For the [[CPU]], it instead of going to Main Memory to retrieve. We can obtain directly from the [[CPU Cache]] which is much faster
36
-
</br>
37
-
38
-
-[[Process (进程)]] accesses only a small portion of the [[Memory Address]] space within a small time interval
Copy file name to clipboardExpand all lines: content/OS/Memory/Memory Safety.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ tags:
9
9
- java
10
10
- cpp
11
11
Creation Date: 2024-01-13, 21:20
12
-
Last Date: 2024-01-22T15:45:33+08:00
12
+
Last Date: 2024-03-18T11:47:06+08:00
13
13
References:
14
14
draft:
15
15
---
@@ -24,10 +24,9 @@ draft:
24
24
</br>
25
25
26
26
### Poor Memory Safety
27
-
-[[Segmentation Fault]]
28
-
- Malicious input to trick the program from doing unwanted things. [70% of reported security vulnerabilities](https://msrc.microsoft.com/blog/2019/07/a-proactive-approach-to-more-secure-code/) in low-level systems are caused by memory corruption. [Memory Safe Languages in Android 13 reduces vulnerabilities](https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html)
29
-
- Backdoor that some hackers are taking advantages of
30
-
- And many other [memory errors](https://en.wikipedia.org/wiki/Memory_safety#Types_of_memory_errors)
27
+
-[[Segmentation Fault]] that leads to a crash in the [[Process (进程)]] or **write into other parts of the process**
28
+
- When hackers can write into other parts of the process, they can use malicious input to trick the program from doing unwanted things. [70% of reported security vulnerabilities](https://msrc.microsoft.com/blog/2019/07/a-proactive-approach-to-more-secure-code/) in low-level systems are caused by memory corruption. [Memory Safe Languages in Android 13 reduces vulnerabilities](https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html)
29
+
- Backdoor that some hackers are taking advantages of, and many other [memory errors](https://en.wikipedia.org/wiki/Memory_safety#Types_of_memory_errors)
Copy file name to clipboardExpand all lines: content/Programming/Pointer.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,24 @@ tags:
8
8
- rust
9
9
- c
10
10
- java
11
+
- go
11
12
Creation Date: 2024-01-04, 14:55
12
-
Last Date: 2024-03-17T18:36:02+08:00
13
+
Last Date: 2024-03-18T19:30:12+08:00
13
14
References:
14
15
draft:
15
16
---
16
17
## Abstract
17
18
---
18
-
- A variable whose value is [[Memory Address]]
19
+
- A [[Datatype]] whose value is [[Memory Address]], and itself is located at a memory address too
20
+
- In the diagram below shows some [[Go]] codes, we create a pointer `var p *int32` and perform [[#Pointer Dereference]] with `*p`
21
+
![[pointer_example.png|600]]
19
22
23
+
>[!bigbrain] Pass data by pointer
24
+
> Pass data to functions by pointer is **memory-efficient**. The data we pass into a function is basically a [[Memory Address]] to access that block of data. If we pass data into functions without pointer. We need to create an entire duplicate of data and pass it to the functions.
25
+
>
26
+
> In [[Java]], data is passed to functions by pointer by default. However in [[Go]], we need to explicity specify the pointer datatype for the function input, then we can pass data by point!
20
27
### Pointee
21
-
- The **actual data** that a pointer points-to inside the [[Address Space#Heap Segment]]
28
+
- The **actual data** that a [[Pointer]] points-to inside the [[Address Space#Heap Segment]]
22
29
23
30
### Pointer Dereference
24
31
- The process of accessing [[#Pointee]] of a [[Pointer]]
@@ -29,6 +36,7 @@ draft:
29
36
-[[Pointer]] that doesn't point to any memory location, basically contains a invalid [[Memory Address]]
30
37
- In [[C]], it is represented by `0` or `nullptr`
31
38
- In [[Java]], it is represented by `null`, [[Datatype#Custom Datatype]] can be `null`
0 commit comments