When coding in C, in code that I can free externally without leaks (tested with valgrind), I have been receiving several annoying misaligned bytes messages (indicating that e.g. something tried to use array access with pointers or vice versa, that sort of thing) or errors allocating memory. I do habitually adopt conventions like freeing my own memory and returning null when a malloc call fails, should I not be doing this? Would it be possible to provide some guidelines for test developers as far as providing information to coders so we know exactly how memory will be freed? This happens most often with, for instance, linked lists or 2-D arrays, in which most coders will be naturally inclined to allocate multiple blocks of memory. If we should allocate a single block of memory to hold everything and try to index within that block, please let us know. Otherwise, generally, the way things are this breaks testing code on our own compilers, and introduces problems completely unrelated to the computer science problems we are trying to solve that are much, much more complicated.
Some template code as far as allocating memory, or even methods we can call such as
object->addRow(varArgsInteger 1, varArgsInteger 2, ...)
would be very awesome. I would be happy writing a
method on my own for solutions if you want to shift responsibility back to me, just template this out please.
@pennell Sorry I did not mean to add this to interview questions :/ Could this be moved to the OJ section?
@pennell No problem, I have just moved it to Comments & Feedback.
@pennell I'm not sure what you meant, did you mean the code you're able to get Accepted in LeetCode is having issues with your local testing? The main purpose of LeetCode is to allow you to focus on the algorithm itself, not worry about language specific things such as freeing memory properly, which you can assume whatever memory you allocated in your function will be freed properly after function return.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.