小编Oma*_*ser的帖子

为什么分配堆内存比分配堆栈内存快得多?

我尝试为堆和堆栈内存中的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)

c++ performance heap-memory stack-memory

5
推荐指数
3
解决办法
230
查看次数

摆脱 spring-boot-starter-data-mongodb 对易受攻击的 Log4J 版本的依赖

鉴于 Log4J 2.x 存在重大远程代码执行漏洞(检查漏洞),我开始查看我的项目依赖项,看看我是否通过例如 slf4j 使用 Log4J,幸运的是我没有。

\n

但我通过spring-boot-starter-data-mongodb. 该软件包的最后一个版本是在2021 年 11 月生成的,因此该问题并未得到缓解。

\n

我怎样才能摆脱依赖而不摆脱spring-boot-starter-data-mongodb因为我严重依赖它。

\n
\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\n
Run Code Online (Sandbox Code Playgroud)\n

spring log4j maven spring-boot spring-mongodb

2
推荐指数
1
解决办法
731
查看次数