Perspective | Write something with perspectives | Blog library
kandi X-RAY | Perspective Summary
kandi X-RAY | Perspective Summary
For English, please visit: kingcos@medium. Perspective,即透视。知道 CSAPP 这本书的同学应该对「Perspective」这个单词不陌生。笔者希望下面的文章能够清晰、透彻地讲清楚所要表述的内容,但个人也深知其不易,如有错误或纰漏,望您积极提出~.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Perspective
Perspective Key Features
Perspective Examples and Code Snippets
Community Discussions
Trending Discussions on Perspective
QUESTION
From within a docker container (in my case running a Debian Busty based image) how can I detect whether it's running under QEMU emulation (as happens on ARM Macs for AMD64 images)?
From the non-docker perspective I've seen suggestion that cpuinfo
might surface this, but it doesn't yield anything directly QEMU related when run from inside my container:
ANSWER
Answered 2022-Mar-28 at 07:26There are more ways to detect that the container is running under the emulation, however the most reliable way is to use identify if the entry point is emulated.
When a container is created, the entry point will become the PID 1. The mechanism that Docker uses for the qemu
emulation will detect that the entry point is for a different architecture and will involve the emulator to emulate the architecture. You can read more about the mechanism used in this post.
Since the entry point will be emulated, the process name will be replaced with the qemu-xxxx
where the xxxx
is the architecture that will be emulated. We can identify if our entry pint process was substituted for qemu
if we call ps -uax
as in the following example:
QUESTION
I'm reading "Computer Systems: A Programmer's Perspective, 3/E" (CS:APP3e) and the following code is an example from the book:
...ANSWER
Answered 2022-Feb-03 at 04:10(This answer is a summary of comments posted above by Antti Haapala, klutt and Peter Cordes.)
GCC allocates more space than "necessary" in order to ensure that the stack is properly aligned for the call to proc
: the stack pointer must be adjusted by a multiple of 16, plus 8 (i.e. by an odd multiple of 8). Why does the x86-64 / AMD64 System V ABI mandate a 16 byte stack alignment?
What's strange is that the code in the book doesn't do that; the code as shown would violate the ABI and, if proc
actually relies on proper stack alignment (e.g. using aligned SSE2 instructions), it may crash.
So it appears that either the code in the book was incorrectly copied from compiler output, or else the authors of the book are using some unusual compiler flags which alter the ABI.
Modern GCC 11.2 emits nearly identical asm (Godbolt) using -Og -mpreferred-stack-boundary=3 -maccumulate-outgoing-args
, the former of which changes the ABI to maintain only 2^3 byte stack alignment, down from the default 2^4. (Code compiled this way can't safely call anything compiled normally, even standard library functions.) -maccumulate-outgoing-args
used to be the default in older GCC, but modern CPUs have a "stack engine" that makes push/pop single-uop so that option isn't the default anymore; push for stack args saves a bit of code size.
One difference from the book's asm is a movl $0, %eax
before the call, because there's no prototype so the caller has to assume it might be variadic and pass AL = the number of FP args in XMM registers. (A prototype that matches the args passed would prevent that.) The other instructions are all the same, and in the same order as whatever older GCC version the book used, except for choice of registers after call proc
returns: it ends up using movslq %edx, %rdx
instead of cltq
(sign-extend with RAX).
CS:APP 3e global edition is notorious for errors in practice problems introduced by the publisher (not the authors), but apparently this code is present in the North American edition, too. So this may be the author's mistake / choice to use actual compiler output with weird options. Unlike some of the bad global edition practice problems, this code could have come unmodified from some GCC version, but only with non-standard options.
Related: Why does GCC allocate more space than necessary on the stack, beyond what's needed for alignment? - GCC has a missed-optimization bug where it sometimes reserves an additional 16 bytes that it truly didn't need to. That's not what's happening here, though.
QUESTION
I'm currently writing a gravity-simulation and I have a small problem displaying the particles with OpenGL.
To get "round" particles, I create a small float-array like this:
...ANSWER
Answered 2022-Jan-19 at 16:51You're in a special case where your fragments are either fully opaque or fully transparent, so it's possible to get depth-testing and blending to work at the same time. The actual problem is, that for depth testing even a fully transparent fragment will store it's depth value. You can prevent the writing by explicitly discarding the fragment in the shader. Something like:
QUESTION
I want to create different types that are uint32_t but are different from compilers perspective -- they can only be compared and assigned to a value of the exact same type. Here is a sample code that I want to achieve:
...ANSWER
Answered 2021-Nov-26 at 22:41You can create a templated archetype and make type-tagged versions of that.
I made this a while back and haven't used it yet, so no testing, but I think the idea should be sound:
QUESTION
In F# if I write
...ANSWER
Answered 2021-Nov-17 at 01:24To expand on the answer given in the comments, the first p
is an immutable value, while the second p
is a function. If you refer to an immutable value multiple times, then (obviously) its value doesn't change over time. But if you invoke a function multiple times, it executes each time, even if the arguments are the same each time.
Note that this is true even for pure functional languages, such as Haskell. If you want to avoid this execution cost, there's a specific technique called memoization that can be used to return cached results when the same inputs occur again. However, memoization has its own costs, and I'm not aware of any mainstream functional language that automatically memoizes all function calls.
QUESTION
I was casting a field of a struct to a *mut
pointer, so I declared that struct's reference as mutable. But then I started getting warnings that the mut
modifier is not required. That seemed weird to me, I'm clearly mutating something, yet declaring it as mut
is unnecessary? This leads me to this minimal example:
ANSWER
Answered 2021-Nov-10 at 15:05Problem #1: potentially_mutate
is incorrectly marked as a safe function while it can cause undefined behavior (e.g. what if I pass in an invalid pointer?). So we need to mark it unsafe
and document our assumptions for safe usage:
QUESTION
I have an array of query elements, where each element can be a term or a subquery containing starting with either "AND" or "OR", and followed by an array of legal query elements, terms or nested subqueries, and so on.
For example, these should all be legal input:
...ANSWER
Answered 2021-Oct-31 at 00:30I think this might be an instance of the TypeScript design limitation reported in microsoft/TypeScript#41164. As mentioned there,
Certain circularities are allowed [...] but other circularities aren't, e.g.
QUESTION
I recently learned there seem to be multiple ways to display an image on a web page.
The first way is to directly assign the URL to an image element's URL
...ANSWER
Answered 2021-Oct-12 at 23:04- The second way is called Data URL, which allow embed small files inline in HTML/CSS, for example:
QUESTION
I make Animation to response mousemove event listener, but the box rotate origin seems like not centered at a middle box and it cant rotate/tilt to left & top.
...ANSWER
Answered 2021-Sep-12 at 20:47Try changing transform-origin
to 50%
QUESTION
I have a project where I want to dynamically build a graph of specific function calls. For example if I have 2 template classes, A and B, where A have a tracked method (saved as graph node) and B has 3 methods (non-tracked method, tracked method and a tracked method which calls A's tracked method), then I want to be able to only register the tracked method calls into the graph object as nodes. The graph object could be a singleton.
...ANSWER
Answered 2021-Aug-30 at 09:57In general, you have 2 strategies:
Instrument your application with some sort of logging/tracing framework, and then try to replicate some sort of tracing mixin-like functionality to apply global/local tracing depending on which parts of code you apply the mixins.
Recompile your code with some sort of tracing instrumentation feature enabled for your compiler or runtime, and then use the associated tracing compiler/runtime-specific tools/frameworks to transform/sift through the data.
For 1, this will require you to manually insert more code or something like _penter/_pexit for MSVC manually or create some sort of ScopedLogger that would (hopefully!) log async to some external file/stream/process. This is not necessarily a bad thing, as having a separate process control the trace tracking would probably be better in the case where the traced process crashes. Regardless, you'd probably have to refactor your code since C++ does not have great first-class support for metaprogramming to refactor/instrument code at a module/global level. However, this is not an uncommon pattern anyways for larger applications; for example, AWS X-Ray is an example of a commercial tracing service (though, typically, I believe it fits the use case of tracing network calls and RPC calls rather than in-process function calls).
For 2, you can try something like utrace or something compiler-specific: MSVC has various tools like Performance Explorer, LLVM has XRay, GCC has gprof
. You essentially compile in a sort of "debug++" mode or there is some special OS/hardware/compiler magic to automatically insert tracing instructions or markers that help the runtime trace your desired code. These tracing-enabled programs/runtimes typically emit to some sort of unique tracing format that must then be read by a unique tracing format reader.
Finally, to dynamically build the graph in memory is a a similar story. Like the tracing strategies above, there are a variety of application and runtime-level libraries to help trace your code that you can interact with programmatically. Even the simplest version of creating ScopedTracer objects that log to a tracing file can then be fitted with a consumer thread that owns and updates the trace graph with whatever desired latency and data durability requirements you have.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Perspective
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page