Closed GoogleCodeExporter closed 9 years ago
Hi,
Thank you very much.
The code was first crafted as a single main() function, and was only later
broken into logical functions. /me n3wb. I guess it shows. :)
I think I was wondering myself how it works regardless of variable going out of
scope, but it worked reliably. (If it wasn't this segment I had in mind, then
there must be some other.) I think I understand the problem now, though.
I shall do as you suggested in 1), because I see no reason for "multiple copies
of the args struct." It is only a single instance holding needed values
globally available to program functions. Furthermore, should I do 2), then I
would have to preassign enough space for these paths (e.g. char
device[PATH_MAX];), which is IMHO a bit redundant.
Thanks again! :-)
Original comment by kernc...@gmail.com
on 2 Aug 2010 at 4:05
My pleasure :-)
Just a thought -- you could also change the char * fields in args to
std::string. This way, you wouldn't have to preallocate large char arrays to
ensure you can store anything the user might want to stuff in there.
Benefits of using std::string are two-fold:
- easy
- unlimited length of argument values (well, limited by available memory only)
- able to have multiple independent copies of args structure
I know you said you don't expect to have multiple copies of args, but in my
experience it's always good to think ahead for these kinds of cases, especially
if it takes a trivial amount of effort. The code can grow and change in ways
you would never predict, and making it bullet proof early can save you lots of
time down the road. Anyway, it's totally your call, just sharing my 2 cents :-)
Potential disadvantages:
- overhead of using std::string and dynamic allocations (these would be trivial
in the case of logkeys, so not really a disadvantage)
Also, if you end up deciding to make logkeys support multiple keyboards, each
thread monitoring a keyboard may need its own copy of args, due to unique log
file name assigned to each keyboard, or other reasons. Having a truly copy-able
args structure would help in this case.
Regards,
Markus.
Original comment by msvil...@gmail.com
on 2 Aug 2010 at 4:15
args' string members are now strings since r73.
thanks. ;)
Original comment by kernc...@gmail.com
on 19 Aug 2010 at 4:46
Original issue reported on code.google.com by
msvil...@gmail.com
on 2 Aug 2010 at 3:35