← Home ← Back to /g/

Thread 107166228

20 posts 2 images /g/
Anonymous No.107166228 [Report] >>107166535 >>107166888 >>107167203 >>107167430 >>107169271 >>107169297 >>107170406
void func()
{
A* a = new A();
a->foo();
A z;
z.foo();
}

Assuming foo is not virtual and ignoring allocator overhead, why might z.foo() be faster than a->foo?

You should be able to solve this
Anonymous No.107166249 [Report] >>107166310
Cache miss. Next thread.
Anonymous No.107166310 [Report]
>>107166249
>Cache miss
Incorrect sar and good morning
Anonymous No.107166535 [Report] >>107166867
>>107166228 (OP)
because it's calling it rather than searching for it?
Anonymous No.107166752 [Report]
Cache hit. Next thread.
Anonymous No.107166867 [Report]
>>107166535
Incorrect, now show bobs n vagene
Anonymous No.107166888 [Report] >>107167557
>>107166228 (OP)
>Assume
>ignore
How about no?
Also the answer is because it's in the stack
Anonymous No.107167203 [Report]
>>107166228 (OP)
because heap management isnt free
Silent Hills P.T No.107167430 [Report]
>>107166228 (OP)
do you homework on your own ranjeesh
Anonymous No.107167557 [Report] >>107170362
>>107166888
The heap can be as fast as the stack, and in this case it is.
Anonymous No.107169271 [Report]
>>107166228 (OP)
sounds like bullshit
it's the same call
maybe if z.foo() is inlined into func, there's some extra optimization that can be done on the resulting code, but that still sounds like bullshit
Anonymous No.107169297 [Report]
>>107166228 (OP)
not a pointer? idk I am a vibecoder now
Anonymous No.107169448 [Report] >>107170362
I am disappointed that /g/ isn't as smart as a YouTube jeet
Anonymous No.107170362 [Report]
>>107167557
Unlikely because the allocation's cacheline may not have been cached before the function entry. It's however almost a given that the top of the CPU stack (whatever is in RSP on x86-64 for instance) is already cached.
This is a retarded question anyway due to an optimizing compiler generating whatever the fuck it wants.
>>107169448
The jeet actually has to try. This board is just hobbyist NEETs.
Anonymous No.107170389 [Report]
stack vs heap
Anonymous No.107170406 [Report]
>>107166228 (OP)
both types of method invocations pass a pointer to the called function
you were wrong yesterday, and you are wrong today
Anonymous No.107170444 [Report] >>107170543
Heap allocation takes an eternity in CPU time compared to moving the stack pointer
Anonymous No.107170543 [Report] >>107170790
>>107170444
that's like a single instruction vs 10 instructions
Anonymous No.107170790 [Report] >>107170808
>>107170543
Syscall you retarded jeet
Anonymous No.107170808 [Report]
>>107170790
it's only a syscall if sbrk() gets called, which should be extremely infrequently