本文翻译自:Pointers vs. values in parameters and return values

In Go there are various ways to return a struct value or slice thereof. 在Go中,有多种方法可以返回struct值或其片段。 For individual ones I've seen: 对于个人而言,我已经看到:

type MyStruct struct {Val int
}func myfunc() MyStruct {return MyStruct{Val: 1}
}func myfunc() *MyStruct {return &MyStruct{}
}func myfunc(s *MyStruct) {s.Val = 1
}

I understand the differences between these. 我了解这些区别。 The first returns a copy of the struct, the second a pointer to the struct value created within the function, the third expects an existing struct to be passed in and overrides the value. 第一个返回该结构的副本,第二个返回指向在函数内创建的结构值的指针,第三个期望传入现有结构并覆盖该值。

I've seen all of these patterns be used in various contexts, I'm wondering what the best practices are regarding these. 我已经看到所有这些模式都可以在各种情况下使用,我想知道关于这些的最佳实践是什么。 When would you use which? 什么时候使用? For instance, the first one could be ok for small structs (because the overhead is minimal), the second for bigger ones. 例如,第一个可能适用于小型结构(因为开销很小),第二个适用于较大的结构。 And the third if you want to be extremely memory efficient, because you can easily reuse a single struct instance between calls. 第三,如果您想提高内存效率,因为您可以轻松地在调用之间重用单个结构实例。 Are there any best practices for when to use which? 有什么最佳实践,何时使用?

Similarly, the same question regarding slices: 同样,关于切片的相同问题:

func myfunc() []MyStruct {return []MyStruct{ MyStruct{Val: 1} }
}func myfunc() []*MyStruct {return []MyStruct{ &MyStruct{Val: 1} }
}func myfunc(s *[]MyStruct) {*s = []MyStruct{ MyStruct{Val: 1} }
}func myfunc(s *[]*MyStruct) {*s = []MyStruct{ &MyStruct{Val: 1} }
}

Again: what are best practices here. 再说一遍:什么是最佳实践。 I know slices are always pointers, so returning a pointer to a slice isn't useful. 我知道切片始终是指针,因此返回指向切片的指针没有用。 However, should I return a slice of struct values, a slice of pointers to structs, should I pass in a pointer to a slice as argument (a pattern used in the Go App Engine API )? 但是,是否应该返回一个结构值切片,一个指向结构的指针切片,是否应该将指向切片的指针作为参数传递( Go App Engine API中使用的模式)?


#1楼

参考:https://stackoom.com/question/1ambd/指针与参数和返回值中的值


#2楼

tl;dr : tl; dr

  • Methods using receiver pointers are common; 使用接收器指针的方法很常见。 the rule of thumb for receivers is , "If in doubt, use a pointer." 接收者的经验法则是 :“如有疑问,请使用指针”。
  • Slices, maps, channels, strings, function values, and interface values are implemented with pointers internally, and a pointer to them is often redundant. 切片,映射,通道,字符串,函数值和接口值是在内部使用指针来实现的,指向它们的指针通常是多余的。
  • Elsewhere, use pointers for big structs or structs you'll have to change, and otherwise pass values , because getting things changed by surprise via a pointer is confusing. 在其他地方,将指针用于大型结构或必须更改的结构,否则传递值 ,因为通过指针使事情意外更改会造成混淆。

One case where you should often use a pointer: 一种应该经常使用指针的情况:

  • Receivers are pointers more often than other arguments. 接收器比其他参数更经常地使用指针。 It's not unusual for methods to modify the thing they're called on, or for named types to be large structs, so the guidance is to default to pointers except in rare cases. 方法修改被调用的东西或命名类型为大型结构并不罕见,因此,在极少数情况下,指南是默认使用指针。
    • Jeff Hodges' copyfighter tool automatically searches for non-tiny receivers passed by value. 杰夫·霍奇斯(Jeff Hodges)的copyfighter工具自动搜索按值传递的非微小接收者。

Some situations where you don't need pointers: 在某些不需要指针的情况下:

  • Code review guidelines suggest passing small structs like type Point struct { latitude, longitude float64 } , and maybe even things a bit bigger, as values, unless the function you're calling needs to be able to modify them in place. 代码审查指南建议将较小的结构(type Point struct { latitude, longitude float64 }传递给值,甚至可能将更大的值作为值传递,除非您调用的函数需要能够就地对其进行修改。

    • Value semantics avoid aliasing situations where an assignment over here changes a value over there by surprise. 值语义避免混叠情况,在此情况下,此处的赋值会意外更改其值。
    • It's not Go-y to sacrifice clean semantics for a little speed, and sometimes passing small structs by value is actually more efficient, because it avoids cache misses or heap allocations. 牺牲干净的语义以加快速度并不是一件容易的事,有时通过值传递小结构实际上会更有效,因为它避免了高速缓存未命中或堆分配。
    • So, Go Wiki's code review comments page suggests passing by value when structs are small and likely to stay that way. 因此,Go Wiki的代码审查评论页建议在结构较小且可能会保持这种状态时按值传递。
    • If the "large" cutoff seems vague, it is; 如果“大”分界线似乎含糊,那就是; arguably many structs are in a range where either a pointer or a value is OK. 可以说,许多结构都在指针或值确定的范围内。 As a lower bound, the code review comments suggest slices (three machine words) are reasonable to use as value receivers. 作为下限,代码审查注释建议切片(三个机器字)可以合理地用作值接收者。 As something nearer an upper bound, bytes.Replace takes 10 words' worth of args (three slices and an int ). 接近上限时, bytes.Replace接受了10个字的args(三个切片和一个int )。
  • For slices , you don't need to pass a pointer to change elements of the array. 对于slices ,您不需要传递指针来更改数组的元素。 io.Reader.Read(p []byte) changes the bytes of p , for instance. io.Reader.Read(p []byte)更改p的字节。 It's arguably a special case of "treat little structs like values," since internally you're passing around a little structure called a slice header (see Russ Cox (rsc)'s explanation ). 可以说这是“对待像值一样的小结构”的特例,因为在内部,您正在传递一个称为切片头的小结构(请参阅Russ Cox(rsc)的说明 )。 Similarly, you don't need a pointer to modify a map or communicate on a channel . 同样,您不需要指针即可修改地图或在channel上进行通信

  • For slices you'll reslice (change the start/length/capacity of), built-in functions like append accept a slice value and return a new one. 对于切片,您将进行切片 (更改其开始/长度/容量),诸如append类的内置函数会接受切片值并返回一个新值。 I'd imitate that; 我会模仿的; it avoids aliasing, returning a new slice helps call attention to the fact that a new array might be allocated, and it's familiar to callers. 它避免了混淆,返回一个新的分片有助于引起人们注意可能分配了一个新数组的事实,并且调用者对此很熟悉。

    • It's not always practical follow that pattern. 遵循这种模式并不总是可行的。 Some tools like database interfaces or serializers need to append to a slice whose type isn't known at compile time. 一些工具,例如数据库接口或序列化器,需要追加到在编译时类型未知的片上。 They sometimes accept a pointer to a slice in an interface{} parameter. 他们有时会在interface{}参数中接受指向切片的指针。
  • Maps, channels, strings, and function and interface values , like slices, are internally references or structures that contain references already, so if you're just trying to avoid getting the underlying data copied, you don't need to pass pointers to them. 映射,通道,字符串以及函数和接口值 (例如切片)是内部引用或已经包含引用的结构,因此,如果您只是试图避免复制基础数据,则无需将指针传递给它们。 (rsc wrote a separate post on how interface values are stored ). (rsc 撰写了有关如何存储接口值的单独文章 )。

    • You still may need to pass pointers in the rarer case that you want to modify the caller's struct: flag.StringVar takes a *string for that reason, for example. 在极少数情况下,您可能仍需要传递指针,以修改调用者的结构: flag.StringVar需要一个*string

Where you use pointers: 使用指针的位置:

  • Consider whether your function should be a method on whichever struct you need a pointer to. 考虑您的函数是否应该是您需要指向的任何结构上的方法。 People expect a lot of methods on x to modify x , so making the modified struct the receiver may help to minimize surprise. 人们期望在x上使用许多方法来修改x ,因此使接收器成为修改后的结构可能有助于最大程度地减少意外。 There are guidelines on when receivers should be pointers. 对于何时应该将接收者作为指针有一些指导 。

  • Functions that have effects on their non-receiver params should make that clear in the godoc, or better yet, the godoc and the name (like reader.WriteTo(writer) ). 对非接收器参数有影响的函数应该在godoc中(最好是godoc和名称)(例如reader.WriteTo(writer) )中reader.WriteTo(writer)

  • You mention accepting a pointer to avoid allocations by allowing reuse; 您提到接受一个指针,以允许通过重用来避免分配。 changing APIs for the sake of memory reuse is an optimization I'd delay until it's clear the allocations have a nontrivial cost, and then I'd look for a way that doesn't force the trickier API on all users: 为了内存重用而更改API是一种优化,我会延迟直到明显知道分配的成本不菲,然后再寻找一种不会对所有用户施加棘手API的方法:

    1. For avoiding allocations, Go's escape analysis is your friend. 为了避免分配,Go的转义分析是您的朋友。 You can sometimes help it avoid heap allocations by making types that can be initialized with a trivial constructor, a plain literal, or a useful zero value like bytes.Buffer . 有时您可以通过创建可以用平凡的构造函数,纯文字或有用的零值(如bytes.Buffer初始化的类型来帮助避免堆分配。
    2. Consider a Reset() method to put an object back in a blank state, like some stdlib types offer. 考虑使用Reset()方法将对象放回空白状态,就像某些stdlib类型提供的那样。 Users who don't care or can't save an allocation don't have to call it. 不在乎或无法保存分配的用户不必调用它。
    3. Consider writing modify-in-place methods and create-from-scratch functions as matching pairs, for convenience: existingUser.LoadFromJSON(json []byte) error could be wrapped by NewUserFromJSON(json []byte) (*User, error) . 考虑写修改就地方法和创建-从划伤的功能匹配对,为方便起见: existingUser.LoadFromJSON(json []byte) error可以通过以下方式包裹NewUserFromJSON(json []byte) (*User, error) Again, it pushes the choice between laziness and pinching allocations to the individual caller. 再次,它在懒惰和捏分配给单个呼叫者之间做出选择。
    4. Callers seeking to recycle memory can let sync.Pool handle some details. 试图回收内存的sync.Pool者可以让sync.Pool处理一些细节。 If a particular allocation creates a lot of memory pressure, you're confident you know when the alloc is no longer used, and you don't have a better optimization available, sync.Pool can help. 如果特定的分配产生了很大的内存压力,您sync.Pool不再使用该分配,并且没有更好的优化方法, sync.Pool可以帮助您。 (CloudFlare published a useful (pre- sync.Pool ) blog post about recycling.) (CloudFlare发布了有关回收的有用的(pre- sync.Pool )博客文章 。)

Finally, on whether your slices should be of pointers: slices of values can be useful, and save you allocations and cache misses. 最后,关于切片是否应该是指针:值切片可以很有用,并且可以节省分配和缓存未命中。 There can be blockers: 可能有阻止者:

  • The API to create your items might force pointers on you, eg you have to call NewFoo() *Foo rather than let Go initialize with the zero value . 用于创建商品的API可能会强制您使用指针,例如,您必须调用NewFoo() *Foo而不是让Go初始化为零值 。
  • The desired lifetimes of the items might not all be the same. 这些项目的期望寿命可能不尽相同。 The whole slice is freed at once; 整个切片立即被释放; if 99% of the items are no longer useful but you have pointers to the other 1%, all of the array remains allocated. 如果99%的项目不再有用,但您有指向其他1%的指针,则所有数组均保持分配状态。
  • Moving items around might cause you problems. 到处移动项目可能会导致您遇到问题。 Notably, append copies items when it grows the underlying array . 值得注意的是,在增长基础数组时append复制项目。 Pointers you got before the append point to the wrong place after, copying can be slower for huge structs, and for eg sync.Mutex copying isn't allowed. 您在append之前获得的指针指向之后的错误位置,对于大型结构,例如, sync.Mutex ,复制可能会变慢。不允许进行sync.Mutex复制。 Insert/delete in the middle and sorting similarly move items around. 在中间插入/删除并类似地移动项目。

Broadly, value slices can make sense if either you get all of your items in place up front and don't move them (eg, no more append s after initial setup), or if you do keep moving them around but you're sure that's OK (no/careful use of pointers to items, items are small enough to copy efficiently, etc.). 广义上讲,如果您将所有项目都放在适当的位置并且不移动它们(例如,在初始设置后不再append ),或者如果您确实继续移动它们,则可以确定价值切片是否合理没关系(无需/谨慎使用指向项目的指针,项目足够小以至于无法有效复制等)。 Sometimes you have to think about or measure the specifics of your situation, but that's a rough guide. 有时您必须考虑或衡量具体情况,但这只是一个粗略的指导。


#3楼

Three main reasons when you would want to use method receivers as pointers: 您希望将方法接收器用作指针的三个主要原因:

  1. "First, and most important, does the method need to modify the receiver? If it does, the receiver must be a pointer." “首先,也是最重要的一点,该方法需要修改接收方吗?如果需要,则接收方必须是指针。”

  2. "Second is the consideration of efficiency. If the receiver is large, a big struct for instance, it will be much cheaper to use a pointer receiver." “第二是效率的考虑。如果接收器很大,例如一个大型结构,则使用指针接收器会便宜得多。”

  3. "Next is consistency. If some of the methods of the type must have pointer receivers, the rest should too, so the method set is consistent regardless of how the type is used" “下一个是一致性。如果该类型的某些方法必须具有指针接收器,则其余方法也应该具有指针接收器,因此,无论如何使用该类型,方法集都是一致的”

Reference : https://golang.org/doc/faq#methods_on_values_or_pointers 参考: https : //golang.org/doc/faq#methods_on_values_or_pointers

Edit : Another important thing is to know the actual "type" that you are sending to function. 编辑:另一个重要的事情是要知道您要发送给功能的实际“类型”。 The type can either be a 'value type' or 'reference type'. 类型可以是“值类型”或“引用类型”。

Even as slices and maps acts as references, we might want to pass them as pointers in scenarios like changing the length of the slice in the function. 即使切片和地图用作引用,我们也可能希望在诸如更改函数中切片长度的情况下将它们作为指针传递。


#4楼

A case where you generally need to return a pointer is when constructing an instance of some stateful or shareable resource . 通常,在构造某些有状态或可共享资源实例时,通常需要返回指针。 This is often done by functions prefixed with New . 这通常是通过以New为前缀的函数来完成的。

Because they represent a specific instance of something and they may need to coordinate some activity, it doesn't make a lot of sense to generate duplicated/copied structures representing the same resource -- so the returned pointer acts as the handle to the resource itself. 因为它们表示某事物的特定实例,并且可能需要协调某些活动,所以生成表示相同资源的重复/复制结构没有多大意义-因此返回的指针充当资源本身的句柄。

Some examples: 一些例子:

  • func NewTLSServer(handler http.Handler) *Server -- instantiate a web server for testing func NewTLSServer(handler http.Handler) *Server实例化Web服务器进行测试
  • func Open(name string) (*File, error) -- return a file access handle func Open(name string) (*File, error) -返回文件访问句柄

In other cases, pointers are returned just because the structure may be too large to copy by default: 在其他情况下,仅由于结构可能太大而无法默认复制而返回指针:

  • func NewRGBA(r Rectangle) *RGBA -- allocate an image in memory func NewRGBA(r Rectangle) *RGBA在内存中分配图像

Alternatively, returning pointers directly could be avoided by instead returning a copy of a structure that contains the pointer internally, but maybe this isn't considered idiomatic: 或者,可以通过改为在内部返回包含指针的结构的副本来避免直接返回指针,但这可能不被认为是惯用的:

  • No such examples found in the standard libraries... 在标准库中找不到此类示例...
  • Related question: Embedding in Go with pointer or with value 相关问题: 使用指针或值嵌入Go中

#5楼

If you can (eg a non-shared resource that does not need to be passed as reference), use a value. 如果可以(例如,不需要传递作为参考的非共享资源),请使用一个值。 By the following reasons: 由于以下原因:

  1. Your code will be nicer and more readable, avoiding pointer operators and null checks. 您的代码将更好,更易读,避免了指针运算符和null检查。
  2. Your code will be safer against Null Pointer panics. 您的代码将更安全地防止Null Pointer恐慌。
  3. Your code will be often faster: yes, faster! 您的代码通常会更快: 是的,更快! Why? 为什么?

Reason 1 : you will allocate less items in the stack. 原因1 :您将在堆栈中分配较少的项目。 Allocating/deallocating from stack is immediate, but allocating/deallocating on Heap may be very expensive (allocation time + garbage collection). 从堆栈分配/取消是立即进行的,但是在堆上分配/取消分配可能会非常昂贵(分配时间+垃圾回收)。 You can see some basic numbers here: http://www.macias.info/entry/201802102230_go_values_vs_references.md 您可以在此处看到一些基本数字: http : //www.macias.info/entry/201802102230_go_values_vs_references.md

Reason 2 : especially if you store returned values in slices, your memory objects will be more compacted in memory: looping a slice where all the items are contiguous is much faster than iterating a slice where all the items are pointers to other parts of the memory. 原因2 :尤其是如果您将返回的值存储在切片中,则内存对象将在内存中更加紧凑:循环所有项都是连续的切片比循环切片所有项都是指向内存其他部分的指针的切片要快得多。 Not for the indirection step but for the increase of cache misses. 不是用于间接步骤,而是用于增加高速缓存未命中率。

Myth breaker : a typical x86 cache line are 64 bytes. 误区 :典型的x86高速缓存行为64字节。 Most structs are smaller than that. 大多数结构都比那个小。 The time of copying a cache line in memory is similar to copying a pointer. 在内存中复制高速缓存行的时间类似于复制指针。

Only if a critical part of your code is slow I would try some micro-optimization and check if using pointers improves somewhat the speed, at the cost of less readability and mantainability. 仅当代码的关键部分慢时,我才会尝试进行一些微优化,并检查使用指针是否在某种程度上提高了速度,但代价是可读性和可维护性较低。

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. 【修真院java小课堂】Memcache是什么?怎么用?

    大家好,我是IT修真院成都分院第18期的学员黄迎旭,一枚正直纯洁善良的java程序员 今天给大家分享一下,修真院官网java(职业)任务五,深度思考中的知识点——Memcache是什么?怎么用? 1.背景介绍 假设又这样一个场景,前台有一个操作,传过来一个请求到后台,这时候需要操作…...

    2024/4/28 6:42:29
  2. if----switch语句

    位移运算符(<<,>>,>>>) “<<”:左移运算符,a<<1 其实就是相当于n乘以2 “>>”:右移运算符,a>>1其实就是相当于n除以2 “>>>” a>>>b可以理解为n除以2的m次方(/运算) if语句switch语句注意事项:switch语句的表达…...

    2024/4/27 23:39:05
  3. Win10 hyper-v 虚拟机下Ubuntu 20.04 + Hyperledger Fabric(超级账本)2.1.0部署教程

    从0开始安装了一次,目前网上教程较少,踩了一些坑,分享&记录以便以后翻阅,有帮助的话请点赞。本文包含:1. hyper-v Ubuntu 20.04 虚拟机创建2. Ubuntu 20.04 + Hyperledger Fabric(超级账本)2.1.0部署3. 测试网络与部署链码正文开始:1. hyper-v Ubuntu 20.04 虚拟机…...

    2024/4/28 22:13:37
  4. vcs+verdi安装教程

    此教程仅供个人学习使用,不得转载安装包下载 点击此链接,关注这个作者微信公众号,然后回复105获取链接(ps:不是我的公众号,感谢该号作者的分享)安装过程 /home下新建synopsys文件夹,然后在此文件夹下新建vcs,scl, verdi三个文件夹,安装过程参考博客1。提示:解压Synop…...

    2024/4/28 17:21:09
  5. 大数据-第05章 zookeeper结构原理图

    执行流程: ①客户端向服务端发送请求 ②sever 服务器接收客户端请求(通过选举机制选举出follower服务器和leader服务器,若sever自身弃权,则变成观察者身份,只能执行后期的命令,没有投票权) ③follower(server)服务器将接收的信息发送到leader(server) ④leader接收fol…...

    2024/4/28 16:27:13
  6. Nginx http_access_module access阶段 限制IP地址访问权限

    http_access_module模块摘要[root@localhost nginx-1.16.1]# ./configure --help | grep http_access_module--without-http_access_module --可以看到access模块是http_access_module模块提供的,编译时默认带此模块访问控制模块 ,该模块可以实现简单的防火墙功能,过滤特…...

    2024/4/20 15:11:35
  7. 学习笔记(3):零基础掌握 Python 入门到实战-字典与集合,你真的了解吗?(三)...

    立即学习:https://edu.csdn.net/course/play/26676/338782?utm_source=blogtoedudict.get(b,laoqi)setdefault(b)...

    2024/4/28 21:20:32
  8. 【渗透测试笔记】之【SQL手动漏洞挖掘】

    SQL 数字型及字符型注入 判断是否存在SQL注入漏洞 假如网址为http://www.xxx.com/1.php?id=1基于报错检测http://www.xxx.com/1.php?id=1 http://www.xxx.com/1.php?id=1" http://www.xxx.com/1.php?id=1% http://www.xxx.com/1.php?id=1( http://www.xxx.com/1.php?…...

    2024/4/28 13:58:04
  9. 数据模型的组成要素

    数据模型的组成要素 一般地讲,数据模型是严格定义的一组概念的集合。这些概念精确地描述了系统的静态特性、动态特性和完整性约束条件。因此,数据模型通常由数据结构、数据操作和数据的完整性约束条件三部分组成。 1、数据结构 **数据结构描述数据库的组成对象以及对象之间的…...

    2024/4/28 9:20:34
  10. Web服务调用和SOA架构+部署docker容器

    一、引言 1.实验目的 理解web Service和SOA架构,构建web 服务。要求: 1)构建校友录服务: 基于RESTful样式,对校友录进行插入、检索、修改、删除、统计等功能;同时,后端数据库使用Mybatis或者Hibernate进行操作。 2)把【校友录服务】部署在docker等容器中。 3)基于spri…...

    2024/4/29 0:38:06
  11. 优秀员工应该具备的11个特质

    这是一篇写给自己,也是写给和我有一样迷茫的人,希望读完以后能对你有些帮助,少走几年弯路。前言 我失眠了好几天,就这么静静的看着天花板。 今年我工作满三年了,近半年也因为生活中的一些不顺,常常胡思乱想。 三年来我干过开发、运维、实施,最后项目越来越成熟,开发任务…...

    2024/4/28 18:09:24
  12. 欧盟的反垄断调查:苹果需要为其不公平的应用商店政策负责

    全文共2309字,预计学习时长8分钟图源:unsplash就在苹果公司的年度开发者大会召开几天前,欧盟向苹果投放了一枚“重磅炸弹”:它开始对苹果的应用商店规则展开反垄断调查。Spotify曾公开呼吁对苹果的反竞争行为进行审查,在此基础之上,该调查主要是为了分析其应用商店的支付…...

    2024/4/28 1:00:29
  13. 一键pebuilder,实现云主机在线装deepin20beta

    本文关键字:deepin云主机版本,在onedrive里装机 国产系统deepin现在已经很精美了,国内很多软硬厂商在慢慢联手uos,。手机os华为方面2020.9月份会发布第一个可用版鸿蒙,这也是一个"uniform os",最近听说美控台积电又要给华为断供了,但其实技术和生态也是俗物,…...

    2024/4/23 3:34:55
  14. 华科图书情报专硕考研复试与读研

    我是2018年入学华科图情全日制的学生,本科是二本双非,本科读的电子商务专业,2020年将毕业。 2020-07-18更新,先来占个坑,等过段时间我工作稳定了,专门写个文章讲我们专业找工作的情况2020-05-11更新 复试(现场形式)的内容: 2020年研究生招生复试的形式为远程复试,学校…...

    2024/4/28 21:10:52
  15. Loadrunner11.0安装与简单使用

    Loadrunner下载:https://pan.baidu.com/s/1TtBlfp9W7FM8MVjmxa5Irw提取码:96d01.解压loadrunner与破解包2.打开文件夹运行setup.exe3.点击loadrunner完整安装程序点击 否单击 下一步然后默认一路下一步即可注意:安装时可能会提示系统缺少组件,安装后组件后,需要重启电脑,…...

    2024/4/28 6:59:15
  16. 星链计划:马斯克的卫星星座将如何瓦解电信行业?

    全文共1544字,预计学习时长6分钟图源:unsplashSpaceX(美国太空探索技术公司)的星链计划是由埃隆马斯克及团队开发的一项卫星星座计划,旨在为世界上各个地区的人们提供互联网接入服务。此计划会在近地轨道大规模发射数以千计的小型卫星,作用于例如iPhone手机的地面手持设备…...

    2024/4/28 6:54:15
  17. idea-java特点

    Java的特点 简单性:程序员只需要理解一些基本的概念,就可以编写出适合各种情况的小程序。Java语言通过提供最基本的的方法啊来完成指定的任务。并通过实现自动垃圾回收基址,大大简化了程序员的的内存管理工作。 面向对象:面向对象的方法基于信息隐蔽和数据抽象类型的概念,…...

    2024/4/28 22:00:12
  18. Python爬取图片实例

    网络爬虫又叫网络蜘蛛、网络机器人等名词。网络爬虫就是自动化的去抓取网络数据,可以在网络中获取满足自己需求的相关信息和资料。通过网络爬虫可以获取大量的数据并且集中在一起,然后就可以进行数据的批量分析和处理了。 目前,很多的企业都在使用网络爬虫进行数据获取,因为…...

    2024/4/28 21:45:33
  19. 全网首发:为什么解码器长时间没有画面?如何解决?

    吾手机进入FreeSwitch,经常长时间没有画面。吾于是经常频繁退出、进入,试图出现画面。很难出现。今天在外面爬山时,然后想起这事。之所以没画面,跟关键帧有关。之前为了解决终端互通问题,吾使用了一个多次发关键帧的办法。那么进会议室能不能如此呢?会议室多次发关键帧。…...

    2024/4/16 10:00:47
  20. 第三章:前端开发学习·第一篇:自主学习-Web浏览器-作者致信

    Web浏览器web 浏览器(通常被称为浏览器)是一个用于检索、展示和遍历在万维网上的信息资源的软件应用程序. 信息资源被定义成统一资源定位符(URI/URL). 它可能是网页, 图片, 视频或者一个内容片断. 超链接的出现使用户能轻松的将浏览器导航到相关的资源, 尽管浏览器主要是为了使…...

    2024/4/21 20:41:11

最新文章

  1. 基于Docker + Locust的数据持久化性能测试系统

    前几天给大家分享了如何使用Locust进行性能测试&#xff0c;但是在实际使用中会发现存在压测的结果无法保存的问题&#xff0c;比如在分布式部署情况下进行压测&#xff0c;每轮压测完成需要释放资源删除容器重新部署后&#xff0c;这段时间的压测结果就都丢失了&#xff0c;如…...

    2024/4/29 1:07:33
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. 【UE5 C++】各个头文件的含义

    #pragma once 预处理程序指令 作用&#xff1a;保护同一个文件不会被多次包含&#xff0c;使得头文件只会被编译一次&#xff0c; #include “CoreMinimal.h” 包含了一套来自UE4的核心编程环境的普遍存在类型 #include “GameFramework/GameModeBase.h” 基于GameModeBas…...

    2024/4/21 20:36:50
  4. 理解 Golang 变量在内存分配中的规则

    为什么有些变量在堆中分配、有些却在栈中分配&#xff1f; 我们先看来栈和堆的特点&#xff1a; 简单总结就是&#xff1a; 栈&#xff1a;函数局部变量&#xff0c;小数据 堆&#xff1a;大的局部变量&#xff0c;函数内部产生逃逸的变量&#xff0c;动态分配的数据&#x…...

    2024/4/26 20:04:06
  5. 实景三维在数字乡村建设中的重要作用

    随着科技的飞速发展&#xff0c;数字乡村建设已成为推动乡村振兴、实现农村现代化的重要途径。实景三维技术作为数字乡村建设的重要支撑&#xff0c;正逐渐在各个领域发挥着不可或缺的作用。本文将从实景三维技术在数字乡村中的应用场景、优势及未来展望等方面进行探讨&#xf…...

    2024/4/26 0:59:18
  6. 416. 分割等和子集问题(动态规划)

    题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义&#xff1a;dp[i][j]表示当背包容量为j&#xff0c;用前i个物品是否正好可以将背包填满&#xff…...

    2024/4/28 4:04:40
  7. 【Java】ExcelWriter自适应宽度工具类(支持中文)

    工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...

    2024/4/28 12:01:04
  8. Spring cloud负载均衡@LoadBalanced LoadBalancerClient

    LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon&#xff0c;直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件&#xff0c;我们讨论Spring负载均衡以Spring Cloud2020之后版本为主&#xff0c;学习Spring Cloud LoadBalance&#xff0c;暂不讨论Ribbon…...

    2024/4/28 16:34:55
  9. TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案

    一、背景需求分析 在工业产业园、化工园或生产制造园区中&#xff0c;周界防范意义重大&#xff0c;对园区的安全起到重要的作用。常规的安防方式是采用人员巡查&#xff0c;人力投入成本大而且效率低。周界一旦被破坏或入侵&#xff0c;会影响园区人员和资产安全&#xff0c;…...

    2024/4/28 18:31:47
  10. VB.net WebBrowser网页元素抓取分析方法

    在用WebBrowser编程实现网页操作自动化时&#xff0c;常要分析网页Html&#xff0c;例如网页在加载数据时&#xff0c;常会显示“系统处理中&#xff0c;请稍候..”&#xff0c;我们需要在数据加载完成后才能继续下一步操作&#xff0c;如何抓取这个信息的网页html元素变化&…...

    2024/4/28 12:01:03
  11. 【Objective-C】Objective-C汇总

    方法定义 参考&#xff1a;https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...

    2024/4/28 12:01:03
  12. 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】

    &#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】&#x1f30f;题目描述&#x1f30f;输入格…...

    2024/4/28 12:01:03
  13. 【ES6.0】- 扩展运算符(...)

    【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数&#xff0…...

    2024/4/28 16:07:14
  14. 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?

    文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕&#xff0c;各大品牌纷纷晒出优异的成绩单&#xff0c;摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称&#xff0c;在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁&#xff0c;多个平台数据都表现出极度异常…...

    2024/4/28 23:42:05
  15. Go语言常用命令详解(二)

    文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令&#xff0c;这些命令可以帮助您在Go开发中进行编译、测试、运行和…...

    2024/4/28 9:00:42
  16. 用欧拉路径判断图同构推出reverse合法性:1116T4

    http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b&#xff0c;我们在 a i a_i ai​ 和 a i 1 a_{i1} ai1​ 之间连边&#xff0c; b b b 同理&#xff0c;则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然&#xff0…...

    2024/4/27 18:40:35
  17. 【NGINX--1】基础知识

    1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息&#xff0c;并安装一些有助于配置官方 NGINX 软件包仓库的软件包&#xff1a; apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...

    2024/4/28 4:14:21
  18. Hive默认分割符、存储格式与数据压缩

    目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限&#xff08;ROW FORMAT&#xff09;配置标准HQL为&#xff1a; ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...

    2024/4/27 13:52:15
  19. 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法

    文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中&#xff0c;传感器和控制器产生大量周…...

    2024/4/27 13:38:13
  20. --max-old-space-size=8192报错

    vue项目运行时&#xff0c;如果经常运行慢&#xff0c;崩溃停止服务&#xff0c;报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中&#xff0c;通过JavaScript使用内存时只能使用部分内存&#xff08;64位系统&…...

    2024/4/28 12:00:58
  21. 基于深度学习的恶意软件检测

    恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞&#xff0c;例如可以被劫持的合法软件&#xff08;例如浏览器或 Web 应用程序插件&#xff09;中的错误。 恶意软件渗透可能会造成灾难性的后果&#xff0c;包括数据被盗、勒索或网…...

    2024/4/28 12:00:58
  22. JS原型对象prototype

    让我简单的为大家介绍一下原型对象prototype吧&#xff01; 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定&#xff0c;每一个构造函数都有一个 prototype 属性&#xff0c;指向另一个对象&#xff0c;所以我们也称为原型对象…...

    2024/4/27 22:51:49
  23. C++中只能有一个实例的单例类

    C中只能有一个实例的单例类 前面讨论的 President 类很不错&#xff0c;但存在一个缺陷&#xff1a;无法禁止通过实例化多个对象来创建多名总统&#xff1a; President One, Two, Three; 由于复制构造函数是私有的&#xff0c;其中每个对象都是不可复制的&#xff0c;但您的目…...

    2024/4/28 7:31:46
  24. python django 小程序图书借阅源码

    开发工具&#xff1a; PyCharm&#xff0c;mysql5.7&#xff0c;微信开发者工具 技术说明&#xff1a; python django html 小程序 功能介绍&#xff1a; 用户端&#xff1a; 登录注册&#xff08;含授权登录&#xff09; 首页显示搜索图书&#xff0c;轮播图&#xff0…...

    2024/4/28 8:32:05
  25. 电子学会C/C++编程等级考试2022年03月(一级)真题解析

    C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...

    2024/4/27 20:28:35
  26. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  27. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  28. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  29. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  30. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  31. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  32. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  33. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  34. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  35. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  36. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  37. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  38. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  39. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  40. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  41. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  42. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  43. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  44. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  45. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57