ASP.NET 上下文中的范围AddScoped是可以理解的,即在请求级别。当涉及到控制台应用程序时,它没有请求上下文,对吗?它将如何表现?
services.AddScoped<SomeServiceClass>();
services.AddSingleton<SomeServiceClass>();
以下 Rust 代码,在 x86_64 平台编译。
#[macro_use]
extern crate lazy_static;
use std::collections::HashMap;
lazy_static! {
static ref HASHMAP: HashMap<u32, &'static str> = {
let mut m = HashMap::new();
m.insert(0, "foo");
m.insert(1, "bar");
m.insert(2, "baz");
m
};
}
fn main() {
// First access to `HASHMAP` initializes it
println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap());
// Any further access to `HASHMAP` just returns the computed value
println!("The entry for `1` is \"{}\".", HASHMAP.get(&1).unwrap());
}
Run Code Online (Sandbox Code Playgroud)
我使用readelf命令查看符号表中HASHMAP变量的大小:
readelf -sW target/debug/deps/section_test-4d7d6a03c56fdde3.o
Symbol table '.symtab' contains 590 …Run Code Online (Sandbox Code Playgroud) 我在互联网上找到的所有关于静态初始化顺序惨败的内容都是关于 C++ 的,但是如果我初始化某种类型 Foo 的全局变量(例如
struct Foo {
int flag;
pthread_key_t key;
void *ptrs[10];
};
Run Code Online (Sandbox Code Playgroud)
我无法初始化类型变量,struct Foo如static struct Foo x = { 0 };?如果我想因为 SIOF 获得正确的代码?
我有一个关于根据基于两列的组合更改 data.frame 中的字符值的问题。我将尝试举一个例子来说明 data.frame 的外观
data <- data.frame(A1 = c("A", "T", "C"), A2 = c("C", "G", "T"),
Ind1 = c("AA", "TG", "TT"), Ind2 = c("CA", "GT", "CT"),
Ind3 = c("AC", "GG", "TC"))
> data
A1 A2 Ind1 Ind2 Ind3
1 A C AA CA AC
2 T G TG GT GG
3 C T TT CT TC
Run Code Online (Sandbox Code Playgroud)
A1我想更改从 Ind1 到 Ind3 的列中的值,这些值与列和的可能组合不匹配A2,例如在第一行中,A1是 anA和A2是 a ,C因此可能的组合将是AA, AC, …
因此,我为一个研究项目拼凑了一个随机数生成器。它的作用是生成一个随机数,然后根据第一个数字的值生成更多随机数。
到目前为止,它工作得很好,我唯一需要它停止做的事情就是生成相同的数字两次。
DATA :
lv_MinI TYPE i VALUE 2,
lv_MaxI TYPE i VALUE 6,
lv_RndI TYPE i,
lv_RndII TYPE i,
lv_i TYPE i VALUE 10.
DO 1 TIMES.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
ran_int_max = lv_MaxI
ran_int_min = lv_MinI
IMPORTING
ran_int = lv_RndI.
WRITE: / lv_RndI.
ULINE.
DO lv_RndI TIMES.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
ran_int_max = lv_MaxI
ran_int_min = lv_MinI
IMPORTING
ran_int = lv_RndII.
WRITE: / lv_RndII.
ENDDO.
ENDDO.
Run Code Online (Sandbox Code Playgroud)
这是输出:
5
4
6
4
3
4
Run Code Online (Sandbox Code Playgroud)
我怎样才能停止生成数字 4 三次?
还有其他人也注意到 Java 21 中 Java 泛型的变化吗?
我们使用Jdbi进行数据库访问,当更新到 Java 21 时,会出现问题,因为无法再确定泛型类型。
在调试时我注意到一个条件
java.lang.reflect.Type type = ...
if (type instanceof Class) {..}
Run Code Online (Sandbox Code Playgroud)
其中type是一个接口,在 Java 17 中计算结果为false,但true在 Java 21 中计算结果为 。
Jdbi的某些泛型依赖于Geantyref库。静态方法GenericTypeReflector.getTypeParameter(..)在 Java 17 中返回泛型类型,但null在 Java 21 中返回。
在发行说明或其他公告中,我找不到任何有关 Java 21 中有关泛型的更改的信息。也没有发现向后兼容的重大更改。
我假设一些内部结构可能由于记录反射 (JEP-440) 或开关的模式匹配 (JEP-441) 而发生了变化,但我已经将这些功能用作 17 预览版功能,没有任何问题。
有人知道是什么导致了这些变化以及为什么吗?
我想我已经明白了。我将问题追溯到记录类的构造函数参数。似乎在 Java 21 中,记录类的默认构造函数的参数不知何故不具有泛型类型。所以对于像这样的记录
record Person(Optional<String> name, Optional<Integer> age) {}
Run Code Online (Sandbox Code Playgroud)
泛型类型String并 …
我想使用facet_wrap 在x 轴上为不同的组绘制不同的值。但是,使用 时scale = "free_x",它会显示每个组内的唯一值。请参阅下面的示例:
library(ggplot2)
set.seed(1234)
nb = rep(LETTERS[1:3],4)
expand.grid(LETTERS[1:3], 1:3)
df = data.frame(ps = paste(rep(c("ps1","gc1"),6)),
cr = rep(LETTERS[1:3],4),
id = rep(x = month.abb[1:4], each = 3));df
df = df[order(df$ps),]
df[df$ps == "ps1","cr"] <- sample(LETTERS[4:6], size = 6, replace = TRUE)
df.all = rbind(df,df,df,df,df,df)
df.all$val = rnorm(n = nrow(df.all))
ggplot(df.all,
aes(x = cr,
y = val)) +
geom_violin() +
facet_wrap(vars(ps, id),
scales = "free_x",
ncol = 4) +
geom_point(position = position_jitter(width = 0.1, height = 0.1), …Run Code Online (Sandbox Code Playgroud) 我有一个运行异步网络工作人员的系统,并定期检查工作人员是否std::exception_ptr存储了一些信息。在这种情况下,它可能会抛出错误,或以其他方式报告错误。简单的例子:
#include <exception>
#include <gmock/gmock.h>
// simplified Network interface and the mock
struct INetwork {
virtual std::exception_ptr getExceptionPtr() const = 0;
};
struct MockedNetwork: public INetwork {
public:
MOCK_METHOD(std::exception_ptr, getExceptionPtr, (), (const override));
};
// simplified system
class System {
public:
System(INetwork& network): _network{network} {}
void run() {
// some complex logic
std::exception_ptr exPtr = _network.getExceptionPtr();
if (exPtr) {
// error handling, or just rethrow
std::rethrow_exception(exPtr);
}
}
private:
INetwork& _network;
};
Run Code Online (Sandbox Code Playgroud)
然后我想测试我的代码是否适用于以下场景
每当网络通过Exception_ptr报告错误时,系统将重新抛出该异常
所以我有这个小 gtest 测试用例:
#include …Run Code Online (Sandbox Code Playgroud) 如何使用 Java 11 中的 ZonedDateTime 对象获得 2023-11-16T09:54:12.123 的结果?
我写:
zdt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
Run Code Online (Sandbox Code Playgroud)
并得到 ISO_LOCAL_DATE_TIME: 2023-11-16T17:25:27.1881768
我想删除只有三位数字的纳秒。
我无法理解 Address Sanitizer 背后的概念 - (stack-use-after-scope)。
#include <iostream>
using namespace std;
class User {
public:
User(){
_name = "No Name";
}
User(string name){
_name = name;
_salary = 0;
}
string getName(){
return _name;
}
int* getRoles(){
return _roles;
}
private:
string _name;
int _salary;
int _roles[5];
};
class Employee {
public:
Employee(User user){
_user = user;
}
User getUser(){
return _user;
}
private:
User _user;
};
int main() {
// your code goes here
User user("User1");
Employee employee(user);
auto …Run Code Online (Sandbox Code Playgroud)