我尝试为堆和堆栈内存中的10 ^ 7整数分配空间,以查看哪一个更快。显然,在堆内存中分配要快得多,但是我不明白原因。
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main()
{
high_resolution_clock::time_point t1 = high_resolution_clock::now();
int *p = new int[1e7];
high_resolution_clock::time_point t2 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>( t2 - t1 ).count();
cout << duration / 1e6 << "\n"; // 5e-06
t1 = high_resolution_clock::now();
vector<int> v(1e7);
t2 = high_resolution_clock::now();
duration = duration_cast<microseconds>( t2 - t1 ).count();
cout << duration / 1e6 << "\n"; // 0.112284
return 0;
}
Run Code Online (Sandbox Code Playgroud) 鉴于 Log4J 2.x 存在重大远程代码执行漏洞(检查漏洞),我开始查看我的项目依赖项,看看我是否通过例如 slf4j 使用 Log4J,幸运的是我没有。
\n但我通过spring-boot-starter-data-mongodb. 该软件包的最后一个版本是在2021 年 11 月生成的,因此该问题并未得到缓解。
我怎样才能摆脱依赖而不摆脱spring-boot-starter-data-mongodb因为我严重依赖它。
\xe2\x9e\x9c mvn dependency:tree | grep -B 5 log4j\n[INFO] +- org.springframework.boot:spring-boot-starter-data-mongodb:jar:2.2.5.RELEASE:compile\n[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.2.5.RELEASE:compile\n[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.5.RELEASE:compile\n[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile\n[INFO] | | | | \\- ch.qos.logback:logback-core:jar:1.2.3:compile\n[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.12.1:compile\n[INFO] | | | | \\- org.apache.logging.log4j:log4j-api:jar:2.12.1:compile\nRun Code Online (Sandbox Code Playgroud)\n c++ ×1
heap-memory ×1
log4j ×1
maven ×1
performance ×1
spring ×1
spring-boot ×1
stack-memory ×1