vtable | Emscripten-based VTable Dumper
kandi X-RAY | vtable Summary
kandi X-RAY | vtable Summary
Emscripten-based VTable Dumper
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 vtable
vtable Key Features
vtable Examples and Code Snippets
Community Discussions
Trending Discussions on vtable
QUESTION
ANSWER
Answered 2022-Apr-08 at 15:31Consider a typical use case of a std::any
: You pass it around in your code, move it dozens of times, store it in a data structure and fetch it again later. In particular, you'll likely return it from functions a lot.
As it is now, the pointer to the single "do everything" function is stored right next to the data in the any
. Given that it's a fairly small type (16 bytes on GCC x86-64), any
fits into a pair of registers. Now, if you return an any
from a function, the pointer to the "do everything" function of the any
is already in a register or on the stack! You can just jump directly to it without having to fetch anything from memory. Most likely, you didn't even have to touch memory at all: You know what type is in the any
at the point you construct it, so the function pointer value is just a constant that's loaded into the appropriate register. Later, you use the value of that register as your jump target. This means there's no chance for misprediction of the jump because there is nothing to predict, the value is right there for the CPU to consume.
In other words: The reason that you get the jump target for free with this implementation is that the CPU must have already touched the any
in some way to obtain it in the first place, meaning that it already knows the jump target and can jump to it with no additional delay.
That means there really is no indirection to speak of with the current implementation if the any
is already "hot", which it will be most of the time, especially if it's used as a return value.
On the other hand, if you use a table of function pointers somewhere in a read-only section (and let the any
instance point to that instead), you'll have to go to memory (or cache) every single time you want to move or access it. The size of an any
is still 16 bytes in this case but fetching values from memory is much, much slower than accessing a value in a register, especially if it's not in a cache. In a lot of cases, moving an any
is as simple as copying its 16 bytes from one location to another, followed by zeroing out the original instance. This is pretty much free on any modern CPU. However, if you go the pointer table route, you'll have to fetch from memory every time, wait for the reads to complete, and then do the indirect call. Now consider that you'll often have to do a sequence of calls on the any
(i.e. move, then destruct) and this will quickly add up. The problem is that you don't just get the address of the function you want to jump to for free every time you touch the any
, the CPU has to fetch it explicitly. Indirect jumps to a value read from memory are quite expensive since the CPU can only retire the jump operation once the entire memory operation has finished. That doesn't just include fetching a value (which is potentially quite fast because of caches) but also address generation, store forwarding buffer lookup, TLB lookup, access validation, and potentially even page table walks. So even if the jump address is computed quickly, the jump won't retire for quite a long while. In general, "indirect-jump-to-address-from-memory" operations are among the worst things that can happen to a CPU's pipeline.
TL;DR: As it is now, returning an any
doesn't stall the CPU's pipeline (the jump target is already available in a register so the jump can retire pretty much immediately). With a table-based solution, returning an any
will stall the pipeline twice: Once to fetch the address of the move function, then another time to fetch the destructor. This delays retirement of the jump quite a bit since it'll have to wait not only for the memory value but also for the TLB and access permission checks.
Code memory accesses, on the other hand, aren't affected by this since the code is kept in microcode form anyway (in the µOp cache). Fetching and executing a few conditional branches in that switch statement is therefore quite fast (and even more so when the branch predictor gets things right, which it almost always does).
QUESTION
I'm trying to build a class in C++ using the QT framework that can inherit from QWidget.
I am attempting to do this by building an AbstractContent
class in a header file that implements QWidget
. Then, HorizContent
inherits from AbstractContent
.
The objective is to have multiple types of "content" all inherit from AbstractContent
so that another class can "hot swap" the type of content it is displaying by simply redefining a single variable.
I am getting Linker errors with the code in it's current state. The code seems to compile just fine - the build fails when it gets to step: [build] [46/46 100% :: 137.186] Linking CXX executable spotify-qt
ANSWER
Answered 2022-Feb-28 at 19:52Posting the answer (thanks to @aschepler for the answer) here to officially close out the question.
The answer was that the build process wasn't bringing the header file in. So I had to add the line:
QUESTION
I couldn't find a proper topic for this question as I haven't got a proper error message.
I'm trying to create a management system for a restaurant which mainly provides pizza as well as other foods(pasta, wings, etc). I want this system to be used by the staff. I have created an abstract class named Foods
that can be used to inherit by other foods. So far I have created a class that inherits from Foods
named Pizza
. Below are my code.
PS: I have used namespaces
for organize foods and staff members separately. As far as I know some people doesn't recommend namespace
and my apologies if you're one of them.
interfaces.h
...ANSWER
Answered 2022-Feb-16 at 10:51You need to implement the static member variables sauces
and drinks
in functions.cpp
and not in interfaces.h
.
functions.cpp
QUESTION
I want to use the new parallel facilities of C++17 but my computer don't.
This works :
...ANSWER
Answered 2022-Feb-12 at 16:45std::accumulate
is meant to apply the binary operation in-order, so it doesn't make any sense to use an execution policy. It doesn't have any overload accepting one (see https://en.cppreference.com/w/cpp/algorithm/accumulate).
If you want to allow out-of-order evaluation with some execution policy, replace std::accumulate
by std::reduce
. std::reduce
may assume commutativity and associativity of the operation to reorder it into any permutation and apply it in any grouping of the elements.
QUESTION
I'm confused about what's going on with lifetimes below:
...ANSWER
Answered 2022-Feb-12 at 01:42Why does Part 1 error?
Rust's type inference is not great at deciding what type a closure should have, when the closure is declared separately from where it is used. When the closure accepts references, the compiler often assumes that there is some specific lifetime that will be involved, not “any lifetime the caller cares to provide” as is actually required here.
In fact, there's an active Rust RFC to improve this by adding another way to specify lifetime parameters on closures. (The RFC also contains an example where making the opposite lifetime assumption would not work.)
what actually happens in part 3? Does Rust make a vtable?
Yes, there's a vtable involved whenever you use dyn
. That's not especially relevant to the root cause here; it's just that the elided lifetime in dyn Fn(&str)
got resolved the way you needed rather than the way you didn't.
Is there a better way? Inlining is ugly and
dyn
is both ugly and makes me wonder about what it actually does.
Placing a closure directly in the function call expression that uses it is very common Rust style, and I recommend you stick to it whenever possible, since it's also the way that works well with type inference.
As a workaround in the case where you need to use a closure more than once, you could pass the closure through a function that constrains its type:
QUESTION
I want to get fields' description from a SQL statement. That is, I want create a function, use a sql statement as the input parameter, returns a jsonb value to decribe the fields' information.
If I know the table name, I can do this:
...ANSWER
Answered 2022-Jan-29 at 04:55It can be easy, if you do it in C extension, but it is almost impossible in PL/pgSQL. For stored procedures, there is not an API, how to detect structure of result without query execution.
QUESTION
I've been struggling with this for longer than I care to admit and would really appreciate some help.
I'm trying to do a project which involves building a linker and scheduler, and thought if I could use some of the functionality that's already been build into LLVM that would be great. I'm using LLVM 10. To get started I did some reading and tried to build this example. Because I plan on embedding LLVM into another project, used this as a reference for 'how to build' the example (see below). I figured the dependencies are just the components from the example CMakeLists.txt.
If I'm not mistaken, I'm getting a linker error and that the component list is the problem, but I'm struggling to resolve it. The way it seems LLVM does linking is by mapping a component name to an library file, but since I don't know which missing library might be causing it I'm stuck. Also, I don't know what llvm_libs is, but adding it to the component list seemed to resolve some of the linker errors I was getting originally. Also also, changing the order of the component list will give me different amounts of errors, which absolutely confounds me.
CMakeLists.txt
...ANSWER
Answered 2022-Jan-25 at 06:29So the following build worked for me and should hopefully be a model for you re: how to use CMake...
QUESTION
I wanted to know the ordering of member variables and vtable pointers in C++ on a diamond virtual inheritance.
Consider the below inheritance:
...ANSWER
Answered 2022-Jan-07 at 12:07what is the correct ordering of member variables and vtable pointers?
There is no "correct ordering". This is not specified in the C++ standard. Each compiler is free to arrange the memory layout of this class hierarchy in any fashion that's compliant with the C++ standard.
A compiler may choose the layout of the class, in this situation, according to some fixed set of rules. Or, a compiler may try to optimize amongst several possibilities and pick a layout that can take advantage of hardware-related factors, like preferred alignment of objects, to try to minimize any required padding. This is entirely up to the compiler.
Furthermore: if you review the text of the C++ standard you will not find even a single mention of anything called a "vtable". It's not there. This is just the most common implementation mechanism for virtual class methods and virtual inheritance. Instead of a pointer, it would be perfectly compliant with the C++ standard for a C++ compiler to use a two-byte index into a table, instead of an entire pointer -- into a table containing records that define each particular class's virtual properties. This would work perfectly fine as long as the number of all classes with virtual properties does not exceed 65536.
In other words: you have no guarantees, whatsoever, what this class's layout will be, in memory, or what its size is. It is not specified in the C++ standard and is entirely implementation-defined.
QUESTION
The unreal engine source code has this bit in a validity check function:
...ANSWER
Answered 2021-Dec-23 at 14:56There are two separate questions here: what does this code do, and does it work?
One common way that vtables are implemented is by storing a pointer to the vtable at the base of the object. So, for example, on a 32-bit machine, the first four bytes of the object would be a pointer to the vtable, and on a 64-bit machine the first eight bytes of the object would be a pointer to the vtable.
With that in mind, let’s think about what *(void**)this
does. The this
pointer points to the base of the object. We want to interpret the beginning of that object as a pointer to a vtable, so we want to get the value of the pointer at the base of the object. However, we don’t have a name for that pointer, so we can’t look it up by name, and because the vtable is set up by the compiler there is no C++ type that corresponds to “a vtable.” So instead, we’ll do the following. We’ll envision the pointer we want to read as being a void*
(a pointer to “something whose type we don’t know.”) The this
pointer is pointing right at that void*
, so we’ll introduce a cast of (void**)this
to say “pretend that this
points at a void*
.” We then dereference that pointer to read the void*
that’s stored there, which is our vtable pointer. Collectively, that gives us *(void**)this
.
The next question is why the null-check works. In a general, this safety check won’t work. It presumes that when space for an object is allocated, the memory is set to all 0s before the object is constructed. Assuming that’s the case, if the vtable pointer hasn’t been set up, then the bytes allocated to it would be 0s, which on some C++ implementations is treated as a null pointer. So the check you’ve listed here would then read the vtable pointer, see if it’s null, and then report an error if it is.
However, there’s a lot of assumptions there - that the memory is nulled out before the object is constructed, that the vtable is at the exact base of the object, etc. I’m not familiar with the specifics of the Unreal engine, but I assume it probably is set up to ensure these requirements are met.
QUESTION
I am trying to write bare metal code in assembly and compile + link it using GCC toolchain. As I know the proper steps is to follow the following steps:
- After restart - MCU has to check vector table and execute reset handler, where I initialize stack pointer.
- Execute main code. In order to complete this task I also need to have respective linker script. When i am trying to execute linker it throws syntax error. Please advice:
- What has to be corrected in linker script
- Correct vtable and handler execution sequence.
Code:
...ANSWER
Answered 2021-Dec-21 at 22:14For what you are doing you can start simpler.
flash.s
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install vtable
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