Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yes, it's a trade off.
In your solution, which does not waste memory, you check the whole string twice.
Another solution would be to first create the wasteful buffer, write the solution into it, now determine the actual size.
Create a new buffer, copy the string from the wasteful buffer, free the wasteful buffer, return the new memory optimized buffer.
But hell, we are optimizing something really tiny and even if the string was quite large, then this third solution would be problematic, because temporarily you need almost twice the memory.
Unused memory isn't leaked. There's just a bunch of undefined bytes after the null byte. It still gets freed when the memory is freed using free, since the OS keeps track of the number of bytes allocated when you call malloc.
Imagine if this was an int array not a char array, a 0 in the middle of the array wouldn't cause any memory to leak.
Code size optimization
I guess we can close this question. If you have any further questions, feel free to open a new one :>
The argument should be in EDI register. The calling convention is in the order: edi, esi, edx, ecx.
Ah ok I see.
IterTools.step
is depricated, so one should usestd.step.by()
instead, and then no imports are needed.I just retested, removing
extern crate itertools
is possible, but if I removeuse itertools::Itertools;
I get the error:I would guess that when the solution was made
extern crate itertools;
was nessesary. Rust 2018 removed the need forextern crate
in a lot of cases.Thanks for the comment!
You have the ability to refactor before, and to fork after submitting :)
That is true. Forked version is better.
You need a solution which is faster or does not use up so much memory.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution