2026-02-18 15:52:55 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="memory-demo">
|
2026-02-23 01:40:56 +08:00
|
|
|
|
<div class="demo-controls">
|
|
|
|
|
|
<button class="allocate-btn wechat" @click="allocate('wechat')" :disabled="!hasFreeSpace">
|
|
|
|
|
|
+ 给微信分配数据
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="allocate-btn game" @click="allocate('game')" :disabled="!hasFreeSpace">
|
|
|
|
|
|
+ 给游戏分配数据
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button class="reset-btn" @click="reset">
|
|
|
|
|
|
↺ 重置
|
|
|
|
|
|
</button>
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
<div class="system-view">
|
|
|
|
|
|
<!-- 虚拟内存试图 -->
|
|
|
|
|
|
<div class="virtual-cluster">
|
|
|
|
|
|
<div class="process-vm wechat">
|
|
|
|
|
|
<div class="title">💬 微信的虚拟内存<br/>(它认为自己独占了空间)</div>
|
|
|
|
|
|
<div class="vm-blocks">
|
|
|
|
|
|
<div v-for="i in 4" :key="'w'+i" class="block" :class="{ filled: wechatBlocks >= i }">
|
|
|
|
|
|
{{ wechatBlocks >= i ? '数据 ' + i : '虚拟空闲' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
2026-02-23 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="process-vm game">
|
|
|
|
|
|
<div class="title">🎮 游戏的虚拟内存<br/>(它也认为自己独占了空间)</div>
|
|
|
|
|
|
<div class="vm-blocks">
|
|
|
|
|
|
<div v-for="i in 4" :key="'g'+i" class="block" :class="{ filled: gameBlocks >= i }">
|
|
|
|
|
|
{{ gameBlocks >= i ? '数据 ' + i : '虚拟空闲' }}
|
|
|
|
|
|
</div>
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
<!-- OS 页表 (映射表) -->
|
|
|
|
|
|
<div class="os-page-table">
|
|
|
|
|
|
<div class="title">保安大叔 (OS 页表)</div>
|
|
|
|
|
|
<div class="table-info">
|
|
|
|
|
|
当程序存数据时,<br/>由我暗中转移到真正的物理缝隙里。
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
2026-02-23 01:40:56 +08:00
|
|
|
|
</div>
|
2026-02-18 15:52:55 +08:00
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
<!-- 物理内存 -->
|
|
|
|
|
|
<div class="physical-memory">
|
|
|
|
|
|
<div class="title">🗄️ 真实的物理内存条<br/>(其实像个大杂烩一样乱)</div>
|
|
|
|
|
|
<div class="pm-blocks">
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-for="(block, idx) in physicalBlocks"
|
|
|
|
|
|
:key="'p'+idx"
|
|
|
|
|
|
class="block"
|
|
|
|
|
|
:class="[block.type, { occupied: block.type !== 'empty' }]"
|
|
|
|
|
|
>
|
|
|
|
|
|
{{ block.label }}
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-02-23 01:40:56 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="explanation-box" v-if="wechatBlocks > 0 || gameBlocks > 0">
|
|
|
|
|
|
💡 发现了没?尽管右侧真正的物理内存已经被塞得像个狗皮膏药,但在左侧的微信和游戏眼里,自己的内存条永远是连续且干净的。更重要的是,微信绝对访问不到橘色的物理块,保证了安全!
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
import { ref, computed } from 'vue'
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
const wechatBlocks = ref(0)
|
|
|
|
|
|
const gameBlocks = ref(0)
|
|
|
|
|
|
|
|
|
|
|
|
// 初始物理内存状态,模拟碎片化
|
|
|
|
|
|
// empty = 空, os = 系统占用
|
|
|
|
|
|
const initialPhysicalBlocks = [
|
|
|
|
|
|
{ type: 'os', label: '系统核心占用' },
|
|
|
|
|
|
{ type: 'empty', label: '空闲' },
|
|
|
|
|
|
{ type: 'os', label: '系统保留' },
|
|
|
|
|
|
{ type: 'empty', label: '空闲' },
|
|
|
|
|
|
{ type: 'empty', label: '空闲' },
|
|
|
|
|
|
{ type: 'empty', label: '空闲' },
|
|
|
|
|
|
{ type: 'os', label: '系统驱动' },
|
|
|
|
|
|
{ type: 'empty', label: '空闲' },
|
2026-02-18 15:52:55 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
const physicalBlocks = ref(JSON.parse(JSON.stringify(initialPhysicalBlocks)))
|
2026-02-18 15:52:55 +08:00
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
const freeSpaceCount = computed(() => {
|
|
|
|
|
|
return physicalBlocks.value.filter(b => b.type === 'empty').length
|
2026-02-18 15:52:55 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
const hasFreeSpace = computed(() => freeSpaceCount.value > 0)
|
|
|
|
|
|
|
|
|
|
|
|
const allocate = (process) => {
|
|
|
|
|
|
if (!hasFreeSpace.value) return
|
|
|
|
|
|
|
|
|
|
|
|
// Find a process block logic
|
|
|
|
|
|
if (process === 'wechat' && wechatBlocks.value < 4) {
|
|
|
|
|
|
wechatBlocks.value++
|
|
|
|
|
|
fillRandomEmptyBlock('wechat', `微信数据 ${wechatBlocks.value}`)
|
|
|
|
|
|
} else if (process === 'game' && gameBlocks.value < 4) {
|
|
|
|
|
|
gameBlocks.value++
|
|
|
|
|
|
fillRandomEmptyBlock('game', `游戏数据 ${gameBlocks.value}`)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fillRandomEmptyBlock = (type, label) => {
|
|
|
|
|
|
const emptyIndices = []
|
|
|
|
|
|
physicalBlocks.value.forEach((b, i) => {
|
|
|
|
|
|
if (b.type === 'empty') emptyIndices.push(i)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
if (emptyIndices.length > 0) {
|
|
|
|
|
|
const randomIndex = emptyIndices[Math.floor(Math.random() * emptyIndices.length)]
|
|
|
|
|
|
physicalBlocks.value[randomIndex] = { type, label }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const reset = () => {
|
|
|
|
|
|
wechatBlocks.value = 0
|
|
|
|
|
|
gameBlocks.value = 0
|
|
|
|
|
|
physicalBlocks.value = JSON.parse(JSON.stringify(initialPhysicalBlocks))
|
|
|
|
|
|
}
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.memory-demo {
|
|
|
|
|
|
background: var(--vp-c-bg-soft);
|
2026-02-23 01:40:56 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
padding: 1.5rem;
|
|
|
|
|
|
margin: 1.5rem 0;
|
|
|
|
|
|
font-family: var(--vp-font-family-base);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.demo-controls {
|
2026-02-18 15:52:55 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 1rem;
|
2026-02-23 01:40:56 +08:00
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
|
|
justify-content: center;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.allocate-btn {
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
padding: 0.6rem 1.2rem;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: all 0.2s;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.allocate-btn:disabled {
|
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
cursor: not-allowed;
|
|
|
|
|
|
filter: grayscale(1);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.allocate-btn.wechat {
|
|
|
|
|
|
background: var(--vp-c-success-1);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.allocate-btn.wechat:not(:disabled):hover {
|
|
|
|
|
|
filter: brightness(1.1);
|
|
|
|
|
|
}
|
|
|
|
|
|
.allocate-btn.game {
|
|
|
|
|
|
background: var(--vp-c-warning-1);
|
|
|
|
|
|
}
|
|
|
|
|
|
.allocate-btn.game:not(:disabled):hover {
|
|
|
|
|
|
filter: brightness(1.1);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.reset-btn {
|
|
|
|
|
|
background: transparent;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
padding: 0.6rem 1.2rem;
|
|
|
|
|
|
border-radius: 8px;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
transition: all 0.2s;
|
|
|
|
|
|
}
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.reset-btn:hover {
|
|
|
|
|
|
background: var(--vp-c-bg-mute);
|
|
|
|
|
|
color: var(--vp-c-text-1);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.system-view {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: stretch;
|
|
|
|
|
|
gap: 1.5rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
@media (max-width: 768px) {
|
|
|
|
|
|
.system-view {
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
}
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.title {
|
|
|
|
|
|
font-size: 0.85rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
font-weight: bold;
|
2026-02-23 01:40:56 +08:00
|
|
|
|
text-align: center;
|
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
|
color: var(--vp-c-text-1);
|
|
|
|
|
|
min-height: 2.5rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.virtual-cluster {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
flex: 2;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.process-vm {
|
2026-02-18 15:52:55 +08:00
|
|
|
|
flex: 1;
|
2026-02-23 01:40:56 +08:00
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
border: 2px dashed var(--vp-c-divider);
|
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
|
padding: 1rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.vm-blocks {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 0.5rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.block {
|
|
|
|
|
|
padding: 0.6rem;
|
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
font-size: 0.8rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
font-weight: bold;
|
2026-02-23 01:40:56 +08:00
|
|
|
|
transition: all 0.3s;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.process-vm .block {
|
|
|
|
|
|
background: var(--vp-c-bg-mute);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
2026-02-23 01:40:56 +08:00
|
|
|
|
color: var(--vp-c-text-3);
|
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
}
|
|
|
|
|
|
.process-vm.wechat .block.filled {
|
|
|
|
|
|
background: rgba(16, 185, 129, 0.15);
|
|
|
|
|
|
border: 1px solid var(--vp-c-success-1);
|
|
|
|
|
|
color: var(--vp-c-success-1);
|
|
|
|
|
|
opacity: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.process-vm.game .block.filled {
|
|
|
|
|
|
background: rgba(245, 158, 11, 0.15);
|
|
|
|
|
|
border: 1px solid var(--vp-c-warning-1);
|
|
|
|
|
|
color: var(--vp-c-warning-1);
|
|
|
|
|
|
opacity: 1;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.os-page-table {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
border: 2px solid var(--vp-c-brand-1);
|
|
|
|
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.05);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.os-page-table .table-info {
|
2026-02-18 15:52:55 +08:00
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
2026-02-23 01:40:56 +08:00
|
|
|
|
text-align: center;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
background: var(--vp-c-bg);
|
2026-02-23 01:40:56 +08:00
|
|
|
|
padding: 0.8rem;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.physical-memory {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
background: var(--vp-c-bg-alt);
|
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
|
border: 2px solid var(--vp-c-text-3);
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.pm-blocks {
|
2026-02-18 15:52:55 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
2026-02-23 01:40:56 +08:00
|
|
|
|
gap: 0.4rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.pm-blocks .block {
|
2026-02-18 15:52:55 +08:00
|
|
|
|
padding: 0.5rem;
|
|
|
|
|
|
border-radius: 4px;
|
2026-02-23 01:40:56 +08:00
|
|
|
|
background: var(--vp-c-bg);
|
|
|
|
|
|
border: 1px solid var(--vp-c-divider);
|
|
|
|
|
|
color: var(--vp-c-text-3);
|
|
|
|
|
|
font-size: 0.75rem;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.pm-blocks .block.os {
|
|
|
|
|
|
background: var(--vp-c-bg-mute);
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
border-style: dashed;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.pm-blocks .block.wechat {
|
|
|
|
|
|
background: var(--vp-c-success-1);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border-color: var(--vp-c-success-1);
|
|
|
|
|
|
animation: popIn 0.3s ease-out;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.pm-blocks .block.game {
|
|
|
|
|
|
background: var(--vp-c-warning-1);
|
|
|
|
|
|
color: white;
|
|
|
|
|
|
border-color: var(--vp-c-warning-1);
|
|
|
|
|
|
animation: popIn 0.3s ease-out;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
@keyframes popIn {
|
|
|
|
|
|
0% { transform: scale(0.9); opacity: 0; }
|
|
|
|
|
|
50% { transform: scale(1.05); }
|
|
|
|
|
|
100% { transform: scale(1); opacity: 1; }
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
.explanation-box {
|
|
|
|
|
|
margin-top: 1.5rem;
|
|
|
|
|
|
padding: 1rem;
|
|
|
|
|
|
background: rgba(16, 185, 129, 0.1);
|
|
|
|
|
|
border-left: 4px solid var(--vp-c-success-1);
|
|
|
|
|
|
border-radius: 0 8px 8px 0;
|
|
|
|
|
|
font-size: 0.95rem;
|
|
|
|
|
|
animation: fadeIn 0.5s;
|
2026-02-18 15:52:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-23 01:40:56 +08:00
|
|
|
|
@keyframes fadeIn {
|
|
|
|
|
|
from { opacity: 0; transform: translateY(10px); }
|
|
|
|
|
|
to { opacity: 1; transform: translateY(0); }
|
|
|
|
|
|
}
|
2026-02-18 15:52:55 +08:00
|
|
|
|
</style>
|