0

I am trying to embed a large resource file (almost 4gb), its a .dat file. However i am running into issues where it throws an error

"Error reading resource 'Sx64.x-none.dat' -- 'Specified argument was out of the range of valid values.

It appears there is a limitation to the size of an embedded resource for Visual studio. Would there be a way to increase the max size? or some other work around for this? I am trying not to use a linked resource or have another file being copied around with the exe.

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
  • 1
    it's not recommended to embed files that huge. is just shipping the file together _with_ the executable not an option? – Franz Gleichmann May 05 '21 at 18:46
  • It's an option, Just a preference to move one file instead multiple ones. Thought I'd reach out to the community to see if anyone had any clever ideas. – Samuel Dague May 05 '21 at 18:48
  • Pretty sure that calling items up out of resources clones them too.. – Caius Jard May 05 '21 at 18:57
  • Which is okay once it pulls them out of the program I can clean it up in my code. Just more visually appealing to see one exe and not an exe, dlls, dat files, etc. Its the small things in life :) – Samuel Dague May 05 '21 at 19:09
  • 2
    Have you tried compiling without Visual Studio through the console? Neglecting the recommendation not to do it, you might succeed in Visual Studio 2022 which is 64-bit. The resources seem to be loaded into memory, so unless that is improved it's going to be difficult. Another option worth trying is a single file executable. – Lemon Sky May 05 '21 at 19:12
  • 1
    Resource size is limited by the maximum size of a memory-mapped file view. Which is 2GB on both the 32-bit and 64-bit versions of Windows. No workaround, this needs to be a file. [Backgrounder](https://stackoverflow.com/a/43549273/17034). – Hans Passant May 05 '21 at 23:38

1 Answers1

2

While in the PE format specification the SizeOfImage value is a 32 bit unsigned integer and can theoretically handle up to 4 GiB, in practice the limit for an executable file is lower. Some user here on stackoverflow has tested this behavior. However it's still possible to make an executable bigger and working (on 64 bit Windows only) but the data must be kept outside of the image sections at End Of File, so the loader won't attempt to allocate it. This is a bad practice and I suggest, as suggested by others in comments, to ship it in a separate file along with your executable.

GrowingBrick
  • 731
  • 4
  • 12
  • Yeah it just looks like I'm going to have to deal with my OCD and ship the exe with the .dat files i need, hurts my head but ill soon forget. Thank you sir. – Samuel Dague May 06 '21 at 12:51