Reply to comment

Passing by const reference

void System::daemonize(const string &dir = "/",
               const std::string &stdinfile = "/dev/null",
               const std::string &stdoutfile = "/dev/null",
               const std::string &stderrfile = "/dev/null")

I assume you are referring to the function header in the code, referenced above. As this code is intended for C++ usage (but can easily be converted to C) I used the very common "const reference" in C++, which is a normal optimization technique.

By using the const reference we are getting the performance of passing by reference (as opposed to passing by copy) combined with the guarantee (const) that the user of the function may not modify the parameters.

This technique is not considered to be "premature optimization," it falls more into the category of "best practices."

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 16 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.