What is the runtime cost of include_bytes! or include_str?

Viewed 1094

The include_bytes! and include_str! macros seem like a mystery to me. I understand that the file is included in the binary, but how does it work at runtime?

  1. When is the file loaded into memory?
  2. Is there any reason not to store the result of include_bytes! / include_str! as a top-level const? Will the file then be in memory for the entire duration of the application runtime?
  3. Are there any penalties for including a "big" file, other than the binary size?
1 Answers

There is no runtime CPU cost.

  1. The file is included in the binary at compile time. When the operating system loads the binary, it is placed into memory along with the executable code.
  2. I would encourage using a static or a const variable for include_bytes / include_str. The included data will be in memory regardless, unless the compiler has determined that it was unused anyway and it was optimized out.
  3. No.

See also:

Related