Andrea
why can't I send a link?
Anonymous
why can't I send a link?
Because there's one day restriction to send links after join
Anonymous
https://codeshare.io/G8llm4 This is the code
Andrea
Thanks
Mar!o
1. You have a leak. 2. Don't realloc for so small numbers. Do it step size using left shifts <<
Andrea
where's the leak? because in the works it prints everything correctly
Andrea
I didn't understand the second one
Mar!o
When realloc fails It returns NULL. So the original array is leaked. Do a backup if the original array like: auto double *const backup = arr; arr = realloc(...); if(!arr) { free(backup); return error.... }
Anonymous
What's the use of Union in this code. Even without union I think we can perform the same code
Mar!o
Not checking for malloc, realloc and calloc is fatal!
Andrea
ok understood .. thank you very much
Anmol
Is there a guide for using openCV in c++ projects on a mac?
Mar!o
Np )
Andrea
and what was I supposed to go through?
Andrea
maybe before I tried and it gave me problems .. however now I try again .. thanks
Andrea
ok I think I understand .. thank you very much
Mar!o
With bitshifts :)
Mar!o
I think the easiest way to do that is with bitshifts: if cap is 1 do cap <<= 1; each time len >= cap
Mar!o
Hmm yeah maybe *=2 is more readable for other people....
Mar!o
But I like bitwise operations :) I mean I also always use (x &(x-1)) to check for power of 2 instead of using the % operator...
Mar!o
U don't like relying on the compiler too much in some situations...
Anonymous
I think the easiest way to do that is with bitshifts: if cap is 1 do cap <<= 1; each time len >= cap
Yeah and you can also trigger undefined behavior since shifts are architecture defined how fancy right?
Anonymous
You mean if they are implemented as logical or arithmetic shifts?
Usually it just directly goes to equivalent of shl/shr instructions in x86
Mar!o
Probably using a loop. But it's possible with bitwise instructions I guess and also with AVX altough is overkill...
Anonymous
That's pretty nice
Mar!o
I have seen an example in AVX/SSE by someone. He loaded the max value, powered and used some vbroadcastps/vpinsrtps instruction to extract it. If I will find again it I'll send you a link!
Mar!o
It was magic
Mar!o
And this Hacker's Delight you are talking about is that a book or article?!
Mar!o
Ah yes you already said
Mar!o
I should read it sounds nice
Mar!o
Maybe I have it in my bookmarks somewhere I will look when I'm home )
Mar!o
Thanks!
Renan
What's the use of Union in this code. Even without union I think we can perform the same code
A union is just multiple variables that share the same memory space. So changing one, will change all others.
Anonymous
Union in above program is just to show example of structure in Union. But it has nothing specific to do
Anonymous
Anonymous
https://www.theaimonk.com/post/dive-into-supervised-machine-learning
Vishal
http://www.vishalchovatiya.com/interface-segregation-principle-in-cpp-solid-as-a-rock/
Anonymous
Hello everyone
Anonymous
I an trying to design a garbage collector. So i want to find out ways to track memory usage of APIs/Functions in C++. Example GetData(structObj, *classObj); If GetData() is leaking memory, it can leak only via structObj and *classObj as they are the only memory we have provided to it. I need to track what is happening to the memory of structObj and *classObj inside GetData(); anybody has any idea how to trace memory info in heap memory?
Anonymous
It's for the learning purpose
Anonymous
I just need a mechanism to detect memory leak?
Renan
It's for the learning purpose
Who never reinvented the wheel?! You learn a lot by doing so. 😅 👍
Renan
As if it was the first design of Hans Boehm... Even this guy had to learn, you do not born an expert.
Renan
I could do it if I tried hard enough and if I had a reason to do it. But I do not. I do not see a problem with reinventing the wheel for learning purposes. It is good exercise.
Anonymous
Your current approach sounds like valgrind's
Anonymous
It's also a very slow approach
Anonymous
Thanks for the info. I will check it out.
Anonymous
i know basics , boss
Anonymous
sorry guys for my iretating questions
Anonymous
?
Asdew
If you have any more of them, please ask either OT (#ot) or the other ~99.999759% of the Internet.
Dima
#ot
Anonymous
Why here in answer after 2 3 it skips 4 and gives 5 6 . I came to know that ++ptr increases 1 so 3 became 4 but (*ptr)[1] would not gave 2 but gave 5 how? Am I forgetting any concept?
Anonymous
a little bit guide pls
Anonymous
In OT.
ok boss
Anonymous
OMG!
Manish
Hi, logger in initialized as below std::unique_ptr<MockHealthCheckEventLogger> logger{ std::make_unique<MockHealthCheckEventLogger>()}; Unit test fails for below code EXPECT_CALL(*logger, logDegraded(_, _)); EXPECT_CALL(*logger, logNoLongerDegraded(_, _)); and test case which have single EXPECT_CALL with *logger are passed. I don't know why this happens? Please help me.
Anonymous
Are ++ptr and ptr++ different
Emir
Are ++ptr and ptr++ different
it’s not for this example
Anonymous
Mar!o
Anonymous
What does that mean 😧
Anonymous
Oh
Anonymous
One more question why it has added 1 to rows only why not column
Emir
*(++ptr)[0] means 4 0(ptr++)[0] means 1
Anonymous
It may be silly ques
Shvmtz
Hi.. can anyone explain me the logic for this code ? "To combine two Strings without using strcat() in c "
Dima
Hi.. can anyone explain me the logic for this code ? "To combine two Strings without using strcat() in c "
take two strings, take their length (strlen), allocate a new one and send characters
Anonymous
I got it tq