391 lines
49 KiB
HTML
391 lines
49 KiB
HTML
<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>一只攻城狮的学习之旅 - 一只攻城狮的学习之旅</title><meta name="author" content="逝水无痕"><meta name="copyright" content="逝水无痕"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="给时光以生命,给岁月以文明"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://zyjblogs.cn/index.html"><link rel="preconnect" href="//cdnjs.cloudflare.com"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://jsd.cdn.zzko.cn/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
|
||
(function() {
|
||
var hm = document.createElement("script");
|
||
hm.src = "https://hm.baidu.com/hm.js?6edd69cc926242ec43e7194677fb8040";
|
||
var s = document.getElementsByTagName("script")[0];
|
||
s.parentNode.insertBefore(hm, s);
|
||
})();
|
||
</script><script>const GLOBAL_CONFIG = {
|
||
root: '/',
|
||
algolia: undefined,
|
||
localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容:${query}","hits_stats":"共找到 ${hits} 篇文章"}},
|
||
translate: undefined,
|
||
noticeOutdate: undefined,
|
||
highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
|
||
copy: {
|
||
success: '复制成功',
|
||
error: '复制错误',
|
||
noSupport: '浏览器不支持'
|
||
},
|
||
relativeDate: {
|
||
homepage: false,
|
||
post: false
|
||
},
|
||
runtime: '天',
|
||
dateSuffix: {
|
||
just: '刚刚',
|
||
min: '分钟前',
|
||
hour: '小时前',
|
||
day: '天前',
|
||
month: '个月前'
|
||
},
|
||
copyright: undefined,
|
||
lightbox: 'fancybox',
|
||
Snackbar: undefined,
|
||
infinitegrid: {
|
||
js: 'https://cdnjs.cloudflare.com/ajax/libs/egjs-infinitegrid/4.11.1/infinitegrid.min.js',
|
||
buttonText: '加载更多'
|
||
},
|
||
isPhotoFigcaption: false,
|
||
islazyload: true,
|
||
isAnchor: false,
|
||
percent: {
|
||
toc: true,
|
||
rightside: true,
|
||
},
|
||
autoDarkmode: true
|
||
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
|
||
title: '一只攻城狮的学习之旅',
|
||
isPost: false,
|
||
isHome: true,
|
||
isHighlightShrink: false,
|
||
isToc: false,
|
||
postUpdate: '2024-10-19 13:43:00'
|
||
}</script><script>(win=>{
|
||
win.saveToLocal = {
|
||
set: (key, value, ttl) => {
|
||
if (ttl === 0) return
|
||
const now = Date.now()
|
||
const expiry = now + ttl * 86400000
|
||
const item = {
|
||
value,
|
||
expiry
|
||
}
|
||
localStorage.setItem(key, JSON.stringify(item))
|
||
},
|
||
|
||
get: key => {
|
||
const itemStr = localStorage.getItem(key)
|
||
|
||
if (!itemStr) {
|
||
return undefined
|
||
}
|
||
const item = JSON.parse(itemStr)
|
||
const now = Date.now()
|
||
|
||
if (now > item.expiry) {
|
||
localStorage.removeItem(key)
|
||
return undefined
|
||
}
|
||
return item.value
|
||
}
|
||
}
|
||
|
||
win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
|
||
const script = document.createElement('script')
|
||
script.src = url
|
||
script.async = true
|
||
script.onerror = reject
|
||
script.onload = script.onreadystatechange = function() {
|
||
const loadState = this.readyState
|
||
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
|
||
script.onload = script.onreadystatechange = null
|
||
resolve()
|
||
}
|
||
|
||
Object.keys(attr).forEach(key => {
|
||
script.setAttribute(key, attr[key])
|
||
})
|
||
|
||
document.head.appendChild(script)
|
||
})
|
||
|
||
win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
|
||
const link = document.createElement('link')
|
||
link.rel = 'stylesheet'
|
||
link.href = url
|
||
if (id) link.id = id
|
||
link.onerror = reject
|
||
link.onload = link.onreadystatechange = function() {
|
||
const loadState = this.readyState
|
||
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
|
||
link.onload = link.onreadystatechange = null
|
||
resolve()
|
||
}
|
||
document.head.appendChild(link)
|
||
})
|
||
|
||
win.activateDarkMode = () => {
|
||
document.documentElement.setAttribute('data-theme', 'dark')
|
||
if (document.querySelector('meta[name="theme-color"]') !== null) {
|
||
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
|
||
}
|
||
}
|
||
win.activateLightMode = () => {
|
||
document.documentElement.setAttribute('data-theme', 'light')
|
||
if (document.querySelector('meta[name="theme-color"]') !== null) {
|
||
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
|
||
}
|
||
}
|
||
const t = saveToLocal.get('theme')
|
||
|
||
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||
const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
|
||
const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
|
||
const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
|
||
|
||
if (t === undefined) {
|
||
if (isLightMode) activateLightMode()
|
||
else if (isDarkMode) activateDarkMode()
|
||
else if (isNotSpecified || hasNoSupport) {
|
||
const now = new Date()
|
||
const hour = now.getHours()
|
||
const isNight = hour <= 6 || hour >= 18
|
||
isNight ? activateDarkMode() : activateLightMode()
|
||
}
|
||
window.matchMedia('(prefers-color-scheme: dark)').addListener(e => {
|
||
if (saveToLocal.get('theme') === undefined) {
|
||
e.matches ? activateDarkMode() : activateLightMode()
|
||
}
|
||
})
|
||
} else if (t === 'light') activateLightMode()
|
||
else activateDarkMode()
|
||
|
||
const asideStatus = saveToLocal.get('aside-status')
|
||
if (asideStatus !== undefined) {
|
||
if (asideStatus === 'hide') {
|
||
document.documentElement.classList.add('hide-aside')
|
||
} else {
|
||
document.documentElement.classList.remove('hide-aside')
|
||
}
|
||
}
|
||
|
||
const detectApple = () => {
|
||
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
|
||
document.documentElement.classList.add('apple')
|
||
}
|
||
}
|
||
detectApple()
|
||
})(window)</script><link rel="stylesheet" href="/css/background.css"><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="一只攻城狮的学习之旅" type="application/atom+xml">
|
||
<link rel="alternate" href="/rss2.xml" title="一只攻城狮的学习之旅" type="application/rss+xml">
|
||
</head><body><script>window.paceOptions = {
|
||
restartOnPushState: false
|
||
}
|
||
|
||
document.addEventListener('pjax:send', () => {
|
||
Pace.restart()
|
||
})
|
||
</script><link rel="stylesheet" href="/css/loading.css"/><script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js"></script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "/img/loading.gif" data-lazy-src="https://zyjblogs.cn/logo.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">26</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">22</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa-fw fas fa-compass"></i><span> 目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 媒体</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bangumis"><i class="fa-fw fa-fw fab fa-youtube"></i><span> 番剧</span></a></li></ul></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://gogs.zyjblogs.cn"><i class="fa-fw fa fa-code"></i><span> 仓库</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('/img/background.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="一只攻城狮的学习之旅"><span class="site-name">一只攻城狮的学习之旅</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa-fw fas fa-compass"></i><span> 目录</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 媒体</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bangumis"><i class="fa-fw fa-fw fab fa-youtube"></i><span> 番剧</span></a></li></ul></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://gogs.zyjblogs.cn"><i class="fa-fw fa fa-code"></i><span> 仓库</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">一只攻城狮的学习之旅</h1><div id="site-subtitle"><span id="subtitle"></span></div><div id="site_social_icons"><a class="social-icon" href="https://github.com/zyjnicemoe" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:1317453947@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title=""><i class="fas fa-rss"></i></a></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/posts/97da918c.html" title="C++编码优化之减少冗余拷贝或赋值"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C++编码优化之减少冗余拷贝或赋值"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/97da918c.html" title="C++编码优化之减少冗余拷贝或赋值">C++编码优化之减少冗余拷贝或赋值</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:32:03.211Z" title="发表于 2024-03-19 14:32:03">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/c/">c++</a></span></div><div class="content">C++编码优化之减少冗余拷贝或赋值临时变量目前遇到的一些产生临时变量的情况:函数实参、函数返回值、隐式类型转换、多余的拷贝。
|
||
1. 函数实参这点应该比较容易理解,函数参数,如果是实参传递的话,函数体里的修改并不会影响调用时传入的参数的值。那么函数体里操作的对象肯定是函数调用的过程中产生出来的。
|
||
那么这种情况我们该怎么办呢?
|
||
如果 callee 中确实要修改这个对象,但是 caller 又不想 callee 的修改影响到原来的值,那么这个临时变量就是必须的了,不需要也没办法避免。
|
||
如果 callee中根本没有修改这个对象,或者 callee 中这个参数本身就是 const 型的,那么将实参传递改为引用传递是个不错的选择(如果是基本类型的函数实参,则没有必要改为引用),可以减少一个临时变量而且不会带来任何损失。
|
||
另外,推荐一个静态代码检查工具 cppcheck,这个工具可以提示非基本类型的 const 实参改为引用。
|
||
2. 函数返回值(返回对象)函数返回值的情况比较复杂,因为编译器在这方面做了很多优化,编译器优化到何种程度我也没追根究底研究过。
|
||
在没开任何优化选项的时候,gcc 也优化了一 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/posts/0.html" title="C语言中三块难啃的硬骨头"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C语言中三块难啃的硬骨头"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/0.html" title="C语言中三块难啃的硬骨头">C语言中三块难啃的硬骨头</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:29:41.998Z" title="发表于 2024-03-19 14:29:41">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/c/">c++</a></span></div><div class="content">C语言中三块难啃的硬骨头C语言在嵌入式学习中是必备的知识,审核大部分操作都要围绕C语言进行,而其中有三块“难啃的硬骨头”几乎是公认级别的。
|
||
|
||
0x01 指针指针公认最难理解的概念,也是让很多初学者选择放弃的直接原因。
|
||
指针之所以难理解,因为指针本身就是一个变量,是一个非常特殊的变量,专门存放地址的变量,这个地址需要给申请空间才能装东西,而且因为是个变量可以中间赋值,这么一倒腾很多人就开始犯晕了,绕不开弯了。C语言之所以被很多高手所喜欢,就是指针的魅力,中间可以灵活的切换,执行效率超高,这点也是让小白晕菜的地方。
|
||
指针是学习绕不过去的知识点,而且学完C语言,下一步紧接着切换到数据结构和算法,指针是切换的重点,指针搞不定下一步进行起来就很难,会让很多人放弃继续学习的勇气。
|
||
指针直接对接内存结构,常见的C语言里面的指针乱指,数组越界根本原因就是内存问题。在指针这个点有无穷无尽的发挥空间。很多编程的技巧都在此集结。
|
||
指针还涉及如何申请释放内存,如果释放不及时就会出现内存泄露的情况,指针是高效好用,但不彻底搞明白对于有些人来说简直就是噩梦。
|
||
在概念方面问题可以参见此前推文《对于C语言指针最详尽的 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/posts/97623f3c.html" title="一起探索C++类内存分布"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="一起探索C++类内存分布"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/97623f3c.html" title="一起探索C++类内存分布">一起探索C++类内存分布</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:28:04.302Z" title="发表于 2024-03-19 14:28:04">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/c/">c++</a></span></div><div class="content">一起探索C++类内存分布C++ 类中内存分布具体是怎么样,尤其是C++中含有继承、虚函数、虚拟继承以及菱形继承等等情况下。
|
||
由于在linux下没有windows下显示直观,我们采用vs2015进行调试。
|
||
|
||
|
||
部署环境
|
||
我们在 属性->C/C++ ->命令行 -> /d1 reportSingleClassLayoutXXX ,XXX表示类名;
|
||
|
||
|
||
|
||
|
||
|
||
单个基础类
|
||
12345678class Base{private: int a; int b;public: void test();};
|
||
|
||
内存分布:
|
||
12345class Base size(8): +-- - 0 | a 4 | b +-- -
|
||
|
||
总结:我们发现普通类的内存分布是根据声明的顺序进行的,成员函数不占用内存。
|
||
|
||
|
||
|
||
|
||
基础类+继承类
|
||
12345678910111213141516class Base{ int a; int b;public: void test();};class Divide :public Base{public: ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/posts/b57ba5ed.html" title="C++内存管理"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C++内存管理"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/b57ba5ed.html" title="C++内存管理">C++内存管理</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:27:19.919Z" title="发表于 2024-03-19 14:27:19">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/c/">c++</a></span></div><div class="content">C++内存管理内存管理是C++最令人切齿痛恨的问题,也是C++最有争议的问题,C++高手从中获得了更好的性能,更大的自由,C++菜鸟的收获则是一遍一遍的检查代码和对C++的痛恨,但内存管理在C++中无处不在,内存泄漏几乎在每个C++程序中都会发生,因此要想成为C++高手,内存管理一关是必须要过的,除非放弃C++,转到Java或者C#,他们的内存管理基本是自动的,当然你也放弃了自由和对内存的支配权,还放弃了C++超绝的性能。本期专题将从内存管理、内存泄漏、内存回收这三个方面来探讨C++内存管理问题。
|
||
1. 内存管理伟大的Bill Gates 曾经失言:
|
||
640K ought to be enough for everybody — Bill Gates 1981
|
||
程序员们经常编写内存管理程序,往往提心吊胆。如果不想触雷,唯一的解决办法就是发现所有潜伏的地雷并且排除它们,躲是躲不了的。本文的内容比一般教科书的要深入得多,读者需细心阅读,做到真正地通晓内存管理。
|
||
1.1 C++内存管理详解1.1.1 内存分配方式1.1.1.1 分配方式简介在C++中,内存分成5个区,他们分别是栈、堆、自由存 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/posts/f5786ffa.html" title="详细分析JDK中Stream的实现原理"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="详细分析JDK中Stream的实现原理"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/f5786ffa.html" title="详细分析JDK中Stream的实现原理">详细分析JDK中Stream的实现原理</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:24:23.059Z" title="发表于 2024-03-19 14:24:23">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/java/">java</a></span></div><div class="content">详细分析JDK中Stream的实现原理前提Stream是JDK1.8中首次引入的,距今已经过去了接近8年时间(JDK1.8正式版是2013年底发布的)。Stream的引入一方面极大地简化了某些开发场景,另一方面也可能降低了编码的可读性(确实有不少人说到Stream会降低代码的可读性,但是在笔者看来,熟练使用之后反而觉得代码的可读性提高了)。这篇文章会花巨量篇幅,详细分析Stream的底层实现原理,参考的源码是JDK11的源码,其他版本JDK可能不适用于本文中的源码展示和相关例子。
|
||
|
||
这篇文章花费了极多时间和精力梳理和编写,希望能够帮助到本文的读者
|
||
|
||
Stream是如何做到向前兼容的Stream是JDK1.8引入的,如要需要JDK1.7或者以前的代码也能在JDK1.8或以上运行,那么Stream的引入必定不能在原来已经发布的接口方法进行修改,否则必定会因为兼容性问题导致老版本的接口实现无法在新版本中运行(方法签名出现异常),猜测是基于这个问题引入了接口默认方法,也就是default关键字。查看源码可以发现,ArrayList的超类Collection和Iterable分别添加了数个def ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/posts/dbb6295a.html" title="HashMap简介"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="HashMap简介"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/dbb6295a.html" title="HashMap简介">HashMap简介</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:22:48.861Z" title="发表于 2024-03-19 14:22:48">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a></span></div><div class="content">HashMap简介
|
||
HashMap核心数据结构Hash表 = 数组 + 线性链表 + 红黑树
|
||
为什么初始容量是2的指数幂?如果创建HashMap时指定的大小不是2的指数就会报错吗?
|
||
1Map map = new HashMap<>(13);
|
||
|
||
|
||
|
||
这行代码在编译的时候也不会报错,那为什么说初始容量是2的指数呢?
|
||
看一下HashMap的构造器
|
||
1234567891011121314151617181920212223public HashMap(int initialCapacity, float loadFactor) { if (initialCapacity < 0) throw new IllegalArgumentException("Illegal initial capacity: " + initialCapacity); if (initialCapacity > MAXIMUM_CAPACITY) initialCapacity = MAXIMUM_CAPACITY; if ( ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/posts/87ddd1f4.html" title="HashMap的最大容量是多少"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="HashMap的最大容量是多少"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/87ddd1f4.html" title="HashMap的最大容量是多少">HashMap的最大容量是多少</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:21:58.654Z" title="发表于 2024-03-19 14:21:58">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a></span></div><div class="content">HashMap的最大容量是多少.首先, HashMap底层是数组+链表, 所以HashMap的容量约等于 数组长度 * 链表长度.因为链表长度不固定,甚至可能链表会是树结构, 所以我们主要讨论数组长度.
|
||
那么, 数组的最大长度是多长呢? 仔细想想, 好像这么多年也没去看过数组的源码(笑).
|
||
1234567一是规范隐含的限制。Java数组的length必须是非负的int,所以它的理论最大值就是java.lang.Integer.MAX_VALUE = 2^31-1 = 2147483647。二是具体的实现带来的限制。这会使得实际的JVM不一定能支持上面说的理论上的最大length。例如说如果有JVM使用uint32_t来记录对象大小的话,那可以允许的最大的数组长度(按元素的个数计算)就会是:(uint32_t的最大值 - 数组对象的对象头大小) / 数组元素大小
|
||
|
||
|
||
|
||
嗯..数组长度理论上可以达到 2^31-1 这么长, 那么HashMap的最大长度也是这么了?
|
||
不, 在HashMap中规定HashMap底层数组的元素最大为 1<<30
|
||
1static final int M ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/posts/f11fd659.html" title="synchronized 实现原理"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="synchronized 实现原理"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/f11fd659.html" title="synchronized 实现原理">synchronized 实现原理</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-19T06:15:38.582Z" title="发表于 2024-03-19 14:15:38">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E5%A4%9A%E7%BA%BF%E7%A8%8B/">多线程</a><i class="fas fa-angle-right article-meta-link"></i><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E5%A4%9A%E7%BA%BF%E7%A8%8B/java/">java</a></span></div><div class="content">synchronized 实现原理2020-03-24
|
||
synchronized 实现原理前言众所周知 synchronized 锁在 Java 中经常使用它的源码是 C++ 实现的,它的实现原理是怎样的呢?本文以 OpenJDK 8 为例探究以下内容。
|
||
|
||
synchronized 是如何工作的
|
||
synchronized 锁升级过程
|
||
重量级锁的队列之间协作过程和策略
|
||
|
||
对象头对象头的内容非常多这里我们只做简单介绍以引出后文。在 JVM 中对象布局分为三块区域:
|
||
|
||
对象头
|
||
实例数据
|
||
对齐填充
|
||
|
||
当线程访问同步块时首先需要获得锁并把相关信息存储在对象头中。所以 wait、notify、notifyAll 这些方法为什么被设计在 Object 中或许你已经找到答案了。
|
||
Hotspot 有两种对象头:
|
||
|
||
数组类型,使用 arrayOopDesc 来描述对象头
|
||
其它,使用 instanceOopDesc 来描述对象头
|
||
|
||
对象头由两部分组成
|
||
|
||
Mark Word:存储自身的运行时数据,例如 HashCode、GC 年龄、锁相关信息等内容。
|
||
Klass Pointer:类型指针指向它的类元数据的指针 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/posts/bd497d25.html" title="N皇后"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="N皇后"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/bd497d25.html" title="N皇后">N皇后</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-18T16:00:00.000Z" title="发表于 2024-03-19 00:00:00">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95/">算法</a></span></div><div class="content">N皇后51. N皇后
|
||
题目描述
|
||
n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
|
||
|
||
|
||
|
||
|
||
上图为 8 皇后问题的一种解法。
|
||
|
||
|
||
给定一个整数 n,返回所有不同的 n 皇后问题的解决方案。
|
||
|
||
|
||
每一种解法包含一个明确的 n 皇后问题的棋子放置方案,该方案中 ‘Q’ 和 ‘.’ 分别代表了皇后和空位。
|
||
示例:
|
||
12345678910111213输入: 4输出: [ [".Q..", // 解法 1 "...Q", "Q...", "..Q."], ["..Q.", // 解法 2 "Q...", "...Q", ".Q.."]]解释: 4 皇后问题存在两个不同的解法。
|
||
|
||
问题分析约束条件为每个棋子所在的行、列、对角线都不能有另一个棋子。
|
||
使用一维数组表示一种解法,下标(index)表示行,值(value)表示该行的Q(皇后)在哪一列。每行只存储一个元素,然后递归到下一行 ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/posts/92fa7813.html" title="状态转移方程"><img class="post-bg" src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="状态转移方程"></a></div><div class="recent-post-info"><a class="article-title" href="/posts/92fa7813.html" title="状态转移方程">状态转移方程</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time datetime="2024-03-18T16:00:00.000Z" title="发表于 2024-03-19 00:00:00">2024-03-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95/">算法</a></span></div><div class="content">状态转移方程定义动态规划中本阶段的状态往往是上一阶段状态和上一阶段决策的结果。若给定了第K阶段的状态Sk以及决策uk(Sk),则第K+1阶段的状态Sk+1也就完全确定。也就是说Sk+1与Sk,uk之间存在一种明确的数量对应关系,记为Tk(Sk,uk),即有Sk+1= Tk(Sk,uk)。 这种用函数表示前后阶段关系的方程,称为状态转移方程。在上例中状态转移方程为 Sk+1= uk(Sk) 。
|
||
设计适用条件
|
||
任何思想方法都有一定的局限性,超出了特定条件,它就失去了作用。同样,动态规划也并不是万能的。适用动态规划的问题必须满足最优化原理和无后效性。
|
||
1.最优化原理(最优子结构性质) 最优化原理可这样阐述:一个最优化策略具有这样的性质,不论过去状态和决策如何,对前面的决策所形成的状态而言,余下的诸决策必须构成最优策略。简而言之,一个最优化策略的子策略总是最优的。一个问题满足最优化原理又称其具有最优子结构性质。
|
||
2.无后效性将各阶段按照一定的次序排列好之后,对于某个给定的阶段状态,它以前各阶段的状态无法直接影响它未来的决策,而只能通过当前的这个状态。换句话说,每个状态都是过 ...</div></div></div><nav id="pagination"><div class="pagination"><span class="page-number current">1</span><a class="page-number" href="/page/2/#content-inner">2</a><a class="page-number" href="/page/3/#content-inner">3</a><a class="extend next" rel="next" href="/page/2/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "/img/loading.gif" data-lazy-src="https://zyjblogs.cn/logo.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">逝水无痕</div><div class="author-info__description">给时光以生命,给岁月以文明</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">26</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">22</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/zyjnicemoe"><i class="fab fa-github"></i><span>GitHub主页</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/zyjnicemoe" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:1317453947@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title=""><i class="fas fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content"><a href="https://zyjblogs.cn">逝水无痕の博客https://zyjblogs.cn迁移到此</a></div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/97da918c.html" title="C++编码优化之减少冗余拷贝或赋值"><img src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C++编码优化之减少冗余拷贝或赋值"/></a><div class="content"><a class="title" href="/posts/97da918c.html" title="C++编码优化之减少冗余拷贝或赋值">C++编码优化之减少冗余拷贝或赋值</a><time datetime="2024-03-19T06:32:03.211Z" title="发表于 2024-03-19 14:32:03">2024-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/0.html" title="C语言中三块难啃的硬骨头"><img src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C语言中三块难啃的硬骨头"/></a><div class="content"><a class="title" href="/posts/0.html" title="C语言中三块难啃的硬骨头">C语言中三块难啃的硬骨头</a><time datetime="2024-03-19T06:29:41.998Z" title="发表于 2024-03-19 14:29:41">2024-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/97623f3c.html" title="一起探索C++类内存分布"><img src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="一起探索C++类内存分布"/></a><div class="content"><a class="title" href="/posts/97623f3c.html" title="一起探索C++类内存分布">一起探索C++类内存分布</a><time datetime="2024-03-19T06:28:04.302Z" title="发表于 2024-03-19 14:28:04">2024-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/b57ba5ed.html" title="C++内存管理"><img src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C++内存管理"/></a><div class="content"><a class="title" href="/posts/b57ba5ed.html" title="C++内存管理">C++内存管理</a><time datetime="2024-03-19T06:27:19.919Z" title="发表于 2024-03-19 14:27:19">2024-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/f5786ffa.html" title="详细分析JDK中Stream的实现原理"><img src= "/img/loading.gif" data-lazy-src="/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="详细分析JDK中Stream的实现原理"/></a><div class="content"><a class="title" href="/posts/f5786ffa.html" title="详细分析JDK中Stream的实现原理">详细分析JDK中Stream的实现原理</a><time datetime="2024-03-19T06:24:23.059Z" title="发表于 2024-03-19 14:24:23">2024-03-19</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
|
||
<i class="fas fa-folder-open"></i>
|
||
<span>分类</span>
|
||
<a class="card-more-btn" href="/categories/" title="查看更多">
|
||
<i class="fas fa-angle-right"></i></a>
|
||
</div>
|
||
<ul class="card-category-list" id="aside-cat-list">
|
||
<li class="card-category-list-item "><a class="card-category-list-link" href="/categories/c/"><span class="card-category-list-name">c++</span><span class="card-category-list-count">11</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/java/"><span class="card-category-list-name">java</span><span class="card-category-list-count">2</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E4%B9%A6/"><span class="card-category-list-name">书</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%A4%9A%E7%BA%BF%E7%A8%8B/"><span class="card-category-list-name">多线程</span><span class="card-category-list-count">2</span></a><ul class="card-category-list child"><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E5%A4%9A%E7%BA%BF%E7%A8%8B/java/"><span class="card-category-list-name">java</span><span class="card-category-list-count">2</span></a></li></ul></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"><span class="card-category-list-name">数据结构</span><span class="card-category-list-count">3</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E7%AE%97%E6%B3%95/"><span class="card-category-list-name">算法</span><span class="card-category-list-count">5</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/%E7%BD%91%E7%BB%9C/"><span class="card-category-list-name">网络</span><span class="card-category-list-count">1</span></a></li>
|
||
</ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" style="font-size: 1.15em; color: rgb(10, 72, 10)">数据结构</a><a href="/tags/c/" style="font-size: 1.15em; color: rgb(179, 51, 191)">c</a><a href="/tags/c/" style="font-size: 1.45em; color: rgb(52, 6, 167)">c++</a><a href="/tags/hashmap/" style="font-size: 1.22em; color: rgb(63, 179, 102)">hashmap</a><a href="/tags/%E7%AE%97%E6%B3%95/" style="font-size: 1.3em; color: rgb(111, 146, 66)">算法</a><a href="/tags/%E5%9B%9E%E6%BA%AF/" style="font-size: 1.15em; color: rgb(64, 135, 65)">回溯</a><a href="/tags/%E9%80%92%E5%BD%92/" style="font-size: 1.15em; color: rgb(59, 39, 83)">递归</a><a href="/tags/springcloud/" style="font-size: 1.15em; color: rgb(176, 122, 9)">springcloud</a><a href="/tags/java/" style="font-size: 1.38em; color: rgb(58, 30, 24)">java</a><a href="/tags/%E6%9F%A5%E6%89%BE/" style="font-size: 1.15em; color: rgb(20, 75, 113)">查找</a><a href="/tags/%E6%A0%91/" style="font-size: 1.15em; color: rgb(135, 145, 170)">树</a><a href="/tags/dp/" style="font-size: 1.15em; color: rgb(0, 115, 86)">dp</a><a href="/tags/%E5%B9%B6%E6%9F%A5%E9%9B%86/" style="font-size: 1.15em; color: rgb(37, 167, 67)">并查集</a><a href="/tags/%E5%9B%BE/" style="font-size: 1.22em; color: rgb(180, 136, 179)">图</a><a href="/tags/chrono/" style="font-size: 1.15em; color: rgb(61, 16, 90)">chrono</a><a href="/tags/cJson/" style="font-size: 1.15em; color: rgb(29, 164, 167)">cJson</a><a href="/tags/%E5%90%8E%E7%AB%AF/" style="font-size: 1.22em; color: rgb(65, 95, 94)">后端</a><a href="/tags/memory/" style="font-size: 1.22em; color: rgb(182, 107, 39)">memory</a><a href="/tags/%E6%8C%87%E9%92%88/" style="font-size: 1.15em; color: rgb(59, 193, 5)">指针</a><a href="/tags/%E7%BD%91%E7%BB%9C/" style="font-size: 1.15em; color: rgb(197, 34, 127)">网络</a><a href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" style="font-size: 1.22em; color: rgb(2, 89, 22)">多线程</a><a href="/tags/stream/" style="font-size: 1.15em; color: rgb(21, 39, 193)">stream</a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>归档</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/03/"><span class="card-archive-list-date">三月 2024</span><span class="card-archive-list-count">12</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/10/"><span class="card-archive-list-date">十月 2023</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2022/02/"><span class="card-archive-list-date">二月 2022</span><span class="card-archive-list-count">7</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2021/08/"><span class="card-archive-list-date">八月 2021</span><span class="card-archive-list-count">5</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">26</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2018-06-06T16:00:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">160.4k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2024-10-19T05:42:59.717Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">©2019 - 2024 By 逝水无痕</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><div><img style="padding-top:2px" src= "/img/loading.gif" data-lazy-src="https://sp-ao.shortpixel.ai/client/q_glossy,ret_img/https://zyjblogs.cn/img/icp.png"><a class="banquan" style="color:#000" href="https://beian.miit.gov.cn/" target="_blank" data-pjax-state="">鄂ICP备19023232号</a></div></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.umd.min.js"></script><script src="https://jsd.cdn.zzko.cn/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://jsd.cdn.zzko.cn/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><div class="js-pjax"><script>window.typedJSFn = {
|
||
init: (str) => {
|
||
window.typed = new Typed('#subtitle', Object.assign({
|
||
strings: str,
|
||
startDelay: 300,
|
||
typeSpeed: 150,
|
||
loop: true,
|
||
backSpeed: 50,
|
||
}, null))
|
||
},
|
||
run: (subtitleType) => {
|
||
if (true) {
|
||
if (typeof Typed === 'function') {
|
||
subtitleType()
|
||
} else {
|
||
getScript('https://jsd.cdn.zzko.cn/npm/typed.js/lib/typed.min.js').then(subtitleType)
|
||
}
|
||
} else {
|
||
subtitleType()
|
||
}
|
||
}
|
||
}
|
||
</script><script>function subtitleType () {
|
||
if (true) {
|
||
typedJSFn.init(["给时光以生命,给岁月以文明"])
|
||
} else {
|
||
document.getElementById("subtitle").textContent = "给时光以生命,给岁月以文明"
|
||
}
|
||
}
|
||
typedJSFn.run(subtitleType)</script></div><script src="https://jsd.cdn.zzko.cn/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
|
||
POWERMODE.shake = false;
|
||
POWERMODE.mobile = false;
|
||
document.body.addEventListener('input', POWERMODE);
|
||
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/pjax/0.2.8/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]
|
||
|
||
var pjax = new Pjax({
|
||
elements: 'a:not([target="_blank"]):not([href="/talking/"])',
|
||
selectors: pjaxSelectors,
|
||
cacheBust: false,
|
||
analytics: false,
|
||
scrollRestoration: false
|
||
})
|
||
|
||
document.addEventListener('pjax:send', function () {
|
||
|
||
// removeEventListener
|
||
btf.removeGlobalFnEvent('pjax')
|
||
btf.removeGlobalFnEvent('themeChange')
|
||
|
||
document.getElementById('rightside').classList.remove('rightside-show')
|
||
|
||
if (window.aplayers) {
|
||
for (let i = 0; i < window.aplayers.length; i++) {
|
||
if (!window.aplayers[i].options.fixed) {
|
||
window.aplayers[i].destroy()
|
||
}
|
||
}
|
||
}
|
||
|
||
typeof typed === 'object' && typed.destroy()
|
||
|
||
//reset readmode
|
||
const $bodyClassList = document.body.classList
|
||
$bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')
|
||
|
||
typeof disqusjs === 'object' && disqusjs.destroy()
|
||
})
|
||
|
||
document.addEventListener('pjax:complete', function () {
|
||
window.refreshFn()
|
||
|
||
document.querySelectorAll('script[data-pjax]').forEach(item => {
|
||
const newScript = document.createElement('script')
|
||
const content = item.text || item.textContent || item.innerHTML || ""
|
||
Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
|
||
newScript.appendChild(document.createTextNode(content))
|
||
item.parentNode.replaceChild(newScript, item)
|
||
})
|
||
|
||
GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()
|
||
|
||
typeof panguInit === 'function' && panguInit()
|
||
|
||
// google analytics
|
||
typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});
|
||
|
||
// baidu analytics
|
||
typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);
|
||
|
||
typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()
|
||
|
||
// prismjs
|
||
typeof Prism === 'object' && Prism.highlightAll()
|
||
})
|
||
|
||
document.addEventListener('pjax:error', e => {
|
||
if (e.request.status === 404) {
|
||
pjax.loadUrl('/404.html')
|
||
}
|
||
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span> 数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html> |