What really annoyed me was why I couldn’t answer such a simple approach when it was questioned to me. You know how frustrating it is to just loose an opportunity just because I wasn't able to answer a simple answer :-/
ssharish
What really annoyed me was why I couldn’t answer such a simple approach when it was questioned to me. You know how frustrating it is to just loose an opportunity just because I wasn't able to answer a simple answer :-/
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
Hi
In this code you are trying to increment the alloc value before allocating the actual memory for the pointer which gives wrong statistics when you analyse the debub prints finaly.same for free API alsoCode:void *debug_malloc(size_t bytes) { allocs++; return malloc(bytes); }
Hi Harish..
What is your comment on this?
Is this question asked in any interviews?
what you replied for this?
I do agree that we could have checked the returned value of malloc before incrementing the alloc. Which would go along with your statistics. Although i guess, I just looking for vague how people can think on it.
Although the malloc isn't thread safe, I would say having wrapper function, counter in the function to keep count on the allocations and deallocation and mutex to be sync with the multi thread would rather be the solution for all. Well there we go; all this i should thought in 30 sec time. Which I missed out, and a big loss in not getting into a big company.
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein