一般而言(总会有例外),多线程最适合IO结合处理(包括网络)。多处理非常适合CPU密集型活动。
因此,您的测试是有缺陷的。
您的意图显然是要进行某种网络爬行,但这并不是在测试代码中发生的,这意味着您的测试是CPU密集型的,因此不适合多线程。鉴于,一旦添加了网络代码,您可能会发现,只要您使用了合适的技术,就可以改善。
查看consturrent.futures中的threadpoolexecutor。您可能会发现这特别有用,因为您可以通过简单地用ProcessPoolExecutor替换ThreadPoolExecutor来交换多处理,这将使您的实验更容易量化
这就是eigen :: ref
是用来的。 “如何写通用但非塑造功能?
请参阅 这样:
void consume_matrix(const Eigen::Ref<const Eigen::MatrixXd>& in);
void produce_matrix(Eigen::Ref<Eigen::MatrixXd> out);
void foo()
{
Eigen::MatrixXd matrix = ...;
produce_matrix(matrix.middleRows(start, len));
consume_matrix(matrix.leftCols(len));
}
存储块引用
eigen不带有非常适合保留矩阵的“借用”块表达式的类型。对于这种情况,我不推荐ref
,因为它太容易了,无法指出临时分配,这很容易导致悬挂的指针。
最终,存储借来的观点是从根本上不安全的操作。但是,如果您绝对必须这样做,我将使用eigen :: Map
。至少这清楚地表明,您不拥有所引用的内存。类似的事情:
struct MatrixReference
{
using map_type = Eigen::Map<
Eigen::MatrixXd, Eigen::Unaligned, Eigen::OuterStride<> >;
map_type matrix;
template<class Derived>
static map_type to_map(const Eigen::DenseBase<Derived>& matrix) noexcept
{
assert(matrix.innerStride() == 1);
return map_type(const_cast<double*>(matrix.derived().data()),
matrix.rows(), matrix.cols(),
Eigen::OuterStride<>(matrix.outerStride()));
}
MatrixReference() noexcept
: matrix(nullptr, 0, 0, Eigen::OuterStride<>(1))
{}
template<class Derived>
explicit MatrixReference(const Eigen::DenseBase<Derived>& matrix) noexcept
: matrix(to_map(matrix))
{}
MatrixReference(const MatrixReference&) = default;
MatrixReference& operator=(const MatrixReference& o) noexcept
{
// placement-new because assignment would overwrite the content
new (&matrix) map_type(o.matrix);
return *this;
}
};
int main()
{
Eigen::MatrixXd mat = Eigen::MatrixXd::Random(4, 5);
MatrixReference ref(mat.topRows(2));
std::cout << mat << "\n\n" << ref.matrix << "\n\n";
}
一个稍微更安全的选项是将shared_ptr
保留到矩阵中,并存储信息单独使用的切片。也许这样:
struct CountedBlockRef
{
std::shared_ptr<Eigen::MatrixXd> matrix;
Eigen::Index first_row, first_col, rows, cols;
using block_type = Eigen::Block<
Eigen::MatrixXd, Eigen::Dynamic, Eigen::Dynamic>;
using const_block_type = Eigen::Block<
const Eigen::MatrixXd, Eigen::Dynamic, Eigen::Dynamic>;
CountedBlockRef() noexcept
: matrix(), first_row(), first_col(), rows(), cols()
{}
CountedBlockRef(std::shared_ptr<Eigen::MatrixXd> matrix,
Eigen::Index first_row, Eigen::Index first_col,
Eigen::Index rows, Eigen::Index cols) noexcept
: matrix(std::move(matrix)),
first_row(first_row),
first_col(first_col),
rows(rows),
cols(cols)
{}
block_type block() noexcept
{ return matrix->block(first_row, first_col, rows, cols); }
const_block_type block() const noexcept
{
const Eigen::MatrixXd& matrix = *this->matrix;
return matrix.block(first_row, first_col, rows, cols);
}
};
int main()
{
std::shared_ptr<Eigen::MatrixXd> matptr =
std::make_shared<Eigen::MatrixXd>(Eigen::MatrixXd::Random(4, 5));
CountedBlockRef aref(matptr, 0, 0, 2, 5);
std::cout << *matptr << "\n\n" << aref.block() << '\n';
}
这样,即使在调整了矩阵和悬空指针大小后,参考文献也将保持有效。只有缩水仍然是一个威胁,但假设您与他们进行了编译,那会被断言所抓住。
我和弹簧靴执行器有类似的现象。在我的情况下,问题是由于某种原因,CGROUP2内存控制器缺少。
jdk.internal.platform.cgroupsubsystemfactory#创建方法期望内存条目。 对其进行检查,
您可以使用$ cat /proc /cgroups
它应该包含一行以“内存”开头的
内核更新之后的问题。
Pricecheckicon需要以JSX形式使用。
更改:
<div>{PriceCheckIcon}</div>
到
<PriceCheckIcon />
这是一个错误,说明它在锡上的作用。 H5标签不应在段落标签中使用。他们表示不同的文字。您应该做一些类似的事情。
<div>
<p><strong>Ans:</strong> The technology we use to build a web application first depends on the project and then everything else. Generally node.js is good for applications that require a persistent connection from the client to the server. Using Node.js can be a great way to build real-time web applications where data will be exchanged quickly through the network. Mongodb is greate database to make web application. Monogo is greate choice if the application have services that you many user and who interact like blogs website. MongoDB is a general-purpose database used in various ways to support web applications in many different industries examples telecommunications, gaming, blog, finances, healthcare, and retail.</p>
<h5>MongoDB use cases</h5>
<ul>
<li>Integrating large amounts of diverse data</li>
<li>Describing complex data structures that evolve</li>
<li>Delivering data in high-performance applications</li>
<li>Supporting hybrid and multi-cloud applications</li>
<li>Supporting agile development and collaboration</li>
</ul>
</div>
这将所有内容包装在DIV中而不是段落标签中,而是将其用于包装文本的第一个块。
“列名”是您实际列名称的占位符。
例如,如果要删除一个名为“姓氏”的列,请使用:
df = df.drop("Surname",axis=1)
您在此处出现的错误清楚地表明,您的数据框中没有列名为“列名”。
有许多错误:
char *data [];
是不是有效的。- 这不是可扩展的。我们想要:
char ** data = null;
并使用realloc
- no 检查
fgets ,因此它将无限 和 not 停止在EOF。
- 第二/后续的调用
fgets
obliterate 来自先前数据的数据。我们需要使用strdup
保留数据。 - 没有 trafing newline的剥离。解决此问题的一种方法是将定系数从
“
”“ ”更改为strtok
“ \ n”
。 - 循环中的最终
printf
试图打印下一个元素,而不是当前的元素。这会产生垃圾,并且是UB(不确定的行为),并具有动态增长的阵列。 - PWD,主机名,用户名不属于MRE(最小可重复的示例)。
这是重构版本。
在下面的代码中,我使用预处理条件来表示旧代码:
#if 0
// old code
#else
// new code
#endif
#if 1
// new code
#endif
无论如何,这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef CWD_MAX_BUF
#define CWD_MAX_BUF 200
#endif
int
main(void)
{
int i = 0;
char input[150];
#if 0
char name[256];
char hostname[HOST_NAME_MAX];
char username[LOGIN_NAME_MAX];
char path[CWD_MAX_BUF];
#endif
#if 0
char *data[];
#else
char **data = NULL;
#endif
// NOTE/BUG: not part of an MRE
#if 0
getcwd(path, CWD_MAX_BUF);
gethostname(hostname, HOST_NAME_MAX);
getlogin_r(username, LOGIN_NAME_MAX);
#endif
for (;;) {
#if 0
printf("[%s@%s %s] $ ", username, hostname, path);
#endif
// NOTE/BUG: you don't stop on EOF
#if 0
fgets(input, 150, stdin);
#else
if (fgets(input, sizeof(input), stdin) == NULL)
break;
#endif
char *token = strtok(input, " \n");
while (token != NULL) {
// NOTE/BUG: we need to enlarge data dynamically
// NOTE/BUG: we have to use strdup -- otherwise, the subsequent fgets will
// obliterate the data from the prior line
#if 0
data[i++] = token;
#else
data = realloc(data,sizeof(*data) * (i + 1));
data[i] = strdup(token);
#endif
printf("TOKEN: %s\n", token);
token = strtok(NULL, " \n");
// NOTE/BUG: tries to print one beyond the end of the actual data
#if 0
printf("data[%i] = %s\n", i + 1, data[i]);
#else
printf("data[%i] = %s\n", i, data[i]);
i++;
#endif
}
}
int count = i;
for (i = 0; i < count; ++i)
printf("final[%i] = %s\n",i,data[i]);
return 0;
}
这是一些测试输入:
the quick brown fox jumps
over the lazy
dog
这是程序输出:
TOKEN: the
data[0] = the
TOKEN: quick
data[1] = quick
TOKEN: brown
data[2] = brown
TOKEN: fox
data[3] = fox
TOKEN: jumps
data[4] = jumps
TOKEN: over
data[5] = over
TOKEN: the
data[6] = the
TOKEN: lazy
data[7] = lazy
TOKEN: dog
data[8] = dog
final[0] = the
final[1] = quick
final[2] = brown
final[3] = fox
final[4] = jumps
final[5] = over
final[6] = the
final[7] = lazy
final[8] = dog
所以,我想如何用USEMEMO替换usecallback
示例?
usecallback
挂钩返回一个回忆的回调函数,该函数传递给了它,而usememo
hook hook hook接收函数回调并返回记忆的值。
usecallback(fn,deps)
等效于usememo(()=&gt; fn,deps)
。
以下是等效的实现:
usecallback
const nameHandler = usecallback(()=&gt; { console.log(“真正的瘦插孔”); },[]); ... &lt; child name = {nameHandler} /&gt;
usememo
const nameHandler = usememo(()=&gt;()=&gt; { console.log(“真正的瘦插孔”); },[]); ... &lt; child name = {nameHandler} /&gt;
usememo
挂钩正在接听 返回 的函数,该函数被用作调用,儿童组成部分。
并不清楚为什么您想这样做。 usecallback
挂钩是要记住传递给儿童组件的回调时要使用的预期挂钩。与usememo
版本中使用的“双重”函数相比,它也更清晰,更容易阅读。我建议坚持使用代码的usecallback
版本。
我从index.html
中评论了&lt; base href =“/”&gt;
,并且我的应用在服务器上显示。
然后我更改了outputpath
angular.json
不包括子域:“ outputpath”:“ dist”,
。
我还将public
在firebase.json
中设置为 include subdomain:“ public”:“ dist/en-en-us” ,
。
为什么在angular.json
和firebase.json
中的不同设置?在这些更改之前,我将angular.json
设置为“ outputpath”:“ dist/language-two13”,
。结果是ng构建
将我的Angular Project转移到dist/language-two13/en-us
中。通过更改此设置,我摆脱了一个子域。
在浏览器中,URL中都不出现子域。
en-us
子域来自我不知道的。我正在为I18N使用Cransloco,但是通过cransporco-root.module.ts
我看到en
和es
作为我项目的语言,不是en-us
。我搜索了整个应用程序,只找到了en-us
的几个实例,仅在将其纠正为en
的代码中,并且从未在会影响转介剂的设置中进行。
我尝试将Crans上的默认语言从en
转换为es
。 Nada Cambios ...没有变化。
我尝试在app.module.ts
中评论Clressoco,但Angular不会编译。
我尝试将文件从dist/en-us/
转移到dist
,删除en-us
文件夹,更改firebase.json
to “ public”:“ dist”,
和评论&lt; base href =“/”&gt;
返回index.html
,并部署到Firebase托管。这很好。
总之,angular.json
设置为无子域的transpile,但是en-us
子域被神奇地插入,因此我设置了firebase.json 纠正这种怪异的行为。
我的帽子是整天处理这些事情的开发人员专业人士!
Chrome.tabs.update的回调几乎立即运行,因此随后的SendMessage在新URL导航之前运行,即在创建页面之前和内容脚本运行之前。
有几种解决方案。
1。使用chrome.storage.Local。
背景脚本:
chrome.omnibox.onInputEntered.addListener(async text => {
await chrome.storage.local.set({text});
await chrome.tabs.update({ url: 'http://www.asknoam.com' });
});
内容脚本:
chrome.storage.local.get('text', ({text}) => {
process(text);
chrome.storage.local.remove('text');
});
chrome.storage.onChanged.addListener(changes => {
if (changes.text) process(changes.text.newValue);
});
subtest.json:
"permissions": ["storage"]
2。等待标签加载
背景脚本:
chrome.omnibox.onInputEntered.addListener(async text => {
const tab = await chrome.tabs.update({ url: 'http://www.asknoam.com' });
chrome.tabs.onUpdated.addListener(function onUpd(tabId, info) {
if (tabId === tab.id && info.status === 'complete') {
chrome.tabs.onUpdated.removeListener(onUpd);
chrome.tabs.sendMessage(tabId, text);
}
});
});
内容脚本:
chrome.runtime.onMessage.addListener(msg => {
sendResponse('bar');
// use msg
// ........
});
所以,
在第一部分中,我知道无法通过反思来找出是否使用了类:(
在第二部分中,如果您用nswag替换swashbuckle,您实际上可以在Swagger UI中拥有这种不错的“之一” - 但是,就我而言,这还不够。
So,
for the first part, what I understand it is not possible to find out if a class is used or not via reflection :(
And for the second part, if you replace the swashbuckle with nswag you are actually able to have this nice "one of" -feature in the swagger UI :) But in my case that is not enough so I guess this is not possible right now.
宣传文档的动态摘要