Home > Enterprise >  Why would one want to embed data into the executable rather than read it from a file?
Why would one want to embed data into the executable rather than read it from a file?

Time:07-24

C23 will be supporting #embed allowing embedding data into an executable to be easier. My question is, however, why would one want to do that? Why not just read it from a file?

CodePudding user response:

If the data should not change after the program is created it makes sense to bundle it with the executable.

An example of this is windows resources (which don't use the new #embed mechanism because it long predates #embed). The resource mechanism allows data such as bitmaps, icons, menus, dialog layout and other static data needed for program operation to be bundled into the program in a way easy for the program to retrieve at run-time. Other systems have similar mechanisms.

Files make sense when the data should be easily changed (such as configuration data), but when the data is needed for the program to operate at all it should be made difficult for a user to change.

  •  Tags:  
  • c
  • Related