Performance wise, is it wrong to embed a file in a resource section of a dll?
This might seem silly, but aim trying to embed some info inside the dll which can later be fetched by some methods, in case the whole solution and documentation is lost and we have only the dll.
What are the downside of doing such a thing?
Is it suggested or prohibited ?

- 24,202
- 35
- 119
- 224
-
Do you not use source control? – leppie Sep 06 '14 at 09:58
-
suppose no,suppose the repository is corupted and i have no back up! – Hossein Sep 06 '14 at 10:01
-
1That's the first problem. [Solve it](http://stackoverflow.com/questions/4609483/version-control-in-visual-studio). – Sriram Sakthivel Sep 06 '14 at 10:11
-
Thats not the case, i am asking for something completely different, Svns doesnt help me here, though i know what they are, but now, they are not helping – Hossein Sep 06 '14 at 10:42
-
What are you trying to accomplish here? What do you want to embed, and what do you want to do with it at runtime? – Krumelur Sep 06 '14 at 10:50
-
2Embedding a resource is very efficient, but use it only to store resources useful for the dll. Don't use it as a bad alternative to source control. There are plenty of free source control options available, and even more free cloud backup services. Putting your backup in a dll seems like a very very bad idea to me. – Falanwe Sep 06 '14 at 13:16
-
@Krumelur:Embedding invaluable info concerning the dll when all and every other means of back up fail me! and dll is only thing i have left. – Hossein Sep 06 '14 at 13:54
1 Answers
Embedded resources are done very efficiently. Under the hood, it uses the demand paged virtual memory capabilities of the operating system. The exact equivalent of a memory-mapped file. In other words, the resource is directly accessible in memory. And you don't pay for the resource until you start using it. The first access to the resource forces it to be read from the file and copied into RAM. And is very cheap to unmap again, the operating system can simply discard the page. There is no way to make it more efficient.
The other side of the medal is that it is permanently mapped into virtual memory. In other words, your process loses the memory space occupied by the resource. You'll run of out of available address space more quickly, an OutOfMemoryException is more likely.
This is not something you normally worry about until you gobble up, say, half a gigabyte in a 32-bit process. And don't fret about at all in a 64-bit process.

- 922,412
- 146
- 1,693
- 2,536
-
Actually i was thinking about embedding one text file or one doc file which contains important and necessary info on the dll itself, I was worried it would have any kind of impact on the performance of the dll since it had to be very optimized. – Hossein Sep 06 '14 at 13:52