CSE 333 21wi Exercise 4
out: Wednesday, January 20, 2021
due: Monday 25, 2021 by 10:00 am,
Exercise Goals
-
Thinking about creating applications in C
-
Writing and designing C code when you don't have starter code
-
More pointer experience
-
More C type system experience
-
Passing arrays as arguments
-
Emphasizing building as distinct from coding
-
Measuring performance
-
Working with someone else's library
-
Possibly a small lesson about writing library code
Setup
Do a git pull
and find directory ex04/
.
Description
Bold indicates the key content in that point. Underlined indicates a task you're asked to complete.
-
Your main task is to implement the standard C library function
memmove
. Your implementation
should have an interface and behavior identical to what man memmmove
describes except
that your method name should be something other than memmove.
Your memmove
implementation may not use any other functions.
memmove
differs from memcpy
in that it works correctly when the source and destination
memory areas overlap. Make sure your implementation has that property.
Your code should reside in a single file, ex04/memmove.c
. You don't need to create a
memmove.h
file because #include <string.h>
will declare the interface
you're implementing. You must create a .h file for your routine because it's name isn't memmove, so
it won't be delcared by <string.h> and the C compiler will want to see a declaration of the routine
before a use (call to) the routine. (Note: We don't care very much what files are called. We'll deal with
it. Calling them memmove.c and memmove.h would be handy, but it isn't a grading criterion.)
-
You should write any mainline you like to help you develop and test your
memmove
implementation.
Call it whatever you like.
-
We will be doing both correctness and performance testing of your implementation, using code we'll supply
as part of grading.
-
We'll use the "library code"
supplied in subdirectory
ex04/c-timer-lib-master/
to time your code,
and you should as well.
(Technically, this is distributed as source, not as a "library.")
We fetched this library from c-timer-lib. We're leaving
it to you to figure out how to use it. Again, that's intentional. It isn't a whole lot of work to figure it
out, and figuring it out is part of the exercise. (Asking someone to tell you exactly what to do in a discussion
board question is not part of the exercise.)
-
The timer code will very likely present some build problems for you.
You're not allowed to modify anything about the library code or which directories files are in,
so you'll have to adjust your build configuration to get their code and your code to build together.
Their code builds, and they even supply a
Makefile
that works on attu
.
(Don't try to use the discussion board to be handed a solution to this. Try to figure out how to fix it.
But if you find yourself about to spend an unreasonable amount of time on it, send email to cse333-staff@cs.)
-
Even once you can build without errors,
you may get a compiler warning that you can't fix without warping your own code in unacceptable ways.
On the other hand, you may not. It depends on just how your code is written. If you get the warning,
you're lucky, in a way, because it will point out how a small thing about the library code can end up causing
issues for clients, and therefore why the "system programmer" creating the library is best off being as
meticulous as humanly possible. (If you don't get a warning, it doesn't mean your code is wrong.)
-
You should organize things so that it's easy to build your testing code to use either your implementation or the
standard library implementation. They have identical interfaces, so nothing about your test code should have
to change. Which is used depends on how your application is built.
-
Edit the
README.md
file we distributed to document how to build your
application to use your memmove
implementation and how to build it to use the standard library
version. We don't expect you to use make. You may use make if you'd like.
-
Include in your
README.md
file a comparison of run times of your and the standard library
implementations of memmove
. Our mainline prints measured performance expressed
in MB/sec. Throughput (i.e., MB/sec) would be an
appropriate way to characterize performance in the README.md
.
- Optional Bonus Activity
There are no points for doing this. I think some people might feel they get a lot out of it and others
will just find it frustrating, so it isn't required. If you do it and feel you got something out of it,
that's the bonus. If you don't do it, that's perfectly okay.
A probably unachievable goal for your implementation is to match or improve upon the performance of the standard C library implementation.
We don't expect you'll achieve that - we didn't.
If your code is much slower than the standard library, think about and try to explain why. (If yours is much
faster, speculate about why the standard library didn't do whatever you did. If they're about equal there
isn't much to say other than that.) You don't need to try to verify your guess as that could be a lot more work
than it's worth.
We have a guess, for instance, but haven't changed our implementation to test how well it does.
Notice that the bonus option is asking you to think about it and formulate some guess(es).
Telling us correctly why the
standard library is faster isn't the point. It would be a mistake to post discussion board entries
about your guesses or asking others to tell you their ideas, or anything close to that.
You can for sure email us to discuss ideas. We're not sure we know the actual answer either, though.
And it would be fine (really great, actually) to use the discussion board to talk about this, say,
24 hours after the assignment is due so that everyone gets a chance to think about it ab initio.
Repeating: It isn't a requirement that your code achieve any particular performance. It isn't a requirement
that your code out-perform the standard library. The optional bonus is optional and isn't a point bonus.
Turn-In
You should tag your code ex04-final
and push to your repository. We will test
your memmove.c
using our testing mainline.
If you require your memmove.c
to be compiled in any particular way, document that in the
README.md
file. We may look at your test code to verify that you used the timer library,
and we may build and test your overall project in some cases. You will not be graded on how extensive your testing
is, just that you did in fact write code to test and time your memmove
implementation and that your
project can be built in the manner you describe.
Maybe Worth Doing
If you haven't run usingvalgrind
, try it to see how
much of a performance impact it has.