R
root
Hello,
I've been thinking about advantages and disadvantages of methods for
storing strings and the like. For instance, I could be storing
things from a configuration or filenames etc. into either char
filename[n] or char *filename, allocating space for the later with
malloc(strlen(x)) or something. What are the advntages/drawbacks of
both methods? Clearly, there's always the chance of n in the first
example not being enough or, on the other hand, much too large; this
could either crash the program or make for a larger memory
footprint. Then again, the second method, with call to malloc()
(and maybe even strlen()), would probably slow the program down a
little. However, the amount of time needed to do this is probably
very low.
Thus is there any rule one should follow in such situations?
Thanks,
andrej
I've been thinking about advantages and disadvantages of methods for
storing strings and the like. For instance, I could be storing
things from a configuration or filenames etc. into either char
filename[n] or char *filename, allocating space for the later with
malloc(strlen(x)) or something. What are the advntages/drawbacks of
both methods? Clearly, there's always the chance of n in the first
example not being enough or, on the other hand, much too large; this
could either crash the program or make for a larger memory
footprint. Then again, the second method, with call to malloc()
(and maybe even strlen()), would probably slow the program down a
little. However, the amount of time needed to do this is probably
very low.
Thus is there any rule one should follow in such situations?
Thanks,
andrej