• Create Account

## Small application / exe

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

10 replies to this topic

### #1Gavin Williams  Members

Posted 09 January 2012 - 11:32 PM

This is a follow-on from a question i posted on stackoverflow. I'm looking at how demo coders prepare small applications, with the intention to make the smallest SlimDX application that I can. I managed to make a window application using C++ with a size of 4096 bytes. But there doesn't seem to be a way to include a static library into C# code, and my goal is to create a single file package. Using Assembly I have created a window application with a size of 2,560 bytes, but I haven't yet looked at making a library using assembly. And I would have the same problem there being unable to incorporate it into a C# Assembly.

When I create the smallest C# application that I can (code following) I get an exe size of 6,144 bytes. Is this the smallest C# application that one can build ? I don't really know anything about CLR under the hood, except that it creates like a CLR-machine language version of the app that is compiled into machine code (first run or every run). Does anyone have any ready hints at the issues I'm facing, even just some reading material on solving this problem would be good. I have seen SlimDX demos but they are large (>100k), seemingly the only small demos are written using C++. but certainly small SlimDX apps can be build, I'm just not sure how small ?

namespace CreateWindowUsingMiniWindowLib
{
static class Program
{
static int Main()
{
return 42;
}
}
}


### #2LorenzoGatti  Members

Posted 10 January 2012 - 03:07 AM

If you need C#, couldn't you cheat with a small C/C++/assembler application (with appropriate linking tricks) that writes out C# sources (with compression and code generation) to temporary files, compiles them and runs them?

Omae Wa Mou Shindeiru

Posted 10 January 2012 - 05:37 AM

I don't think there's any chance of using SlimDX for a 4k intro, assuming you want to get it past the rules for say Assembly. The problem is that SlimDX needs a DLL as well as the exe.

If you want to get your C++ exe smaller, try http://crinkler.net/

### #4Gavin Williams  Members

Posted 10 January 2012 - 06:52 AM

Thanks for that, I didn't know about Assembly.org, that's great. I have my C++ exe down to 3,584 bytes now, and haven't tried anything like Crinkler yet. So I'm getting there. Reading about the PE/COFF file formats at the moment (exciting stuff ;P) Im thinking I'll work out how to put together some direct x, coz I want to use this little file. I don't know if referencing SlimDX dlls would be a problem as the same has to be done with directX (doesn't it ?). And presumably SlimDX could be considered system software as much as DX. But until I learn more on how the .NET file format works, and code-generation options, it's not an option for 4k.

### #5NightCreature83  Members

Posted 10 January 2012 - 07:42 AM

Thanks for that, I didn't know about Assembly.org, that's great. I have my C++ exe down to 3,584 bytes now, and haven't tried anything like Crinkler yet. So I'm getting there. Reading about the PE/COFF file formats at the moment (exciting stuff ;P) Im thinking I'll work out how to put together some direct x, coz I want to use this little file. I don't know if referencing SlimDX dlls would be a problem as the same has to be done with directX (doesn't it ?). And presumably SlimDX could be considered system software as much as DX. But until I learn more on how the .NET file format works, and code-generation options, it's not an option for 4k.

Well the wikipedia page on sharpdx tells you he wanted to create a slimdx version that didnt need C++/CLI for API calls to direct3d apis.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max

### #6Antheus  Members

Posted 10 January 2012 - 09:22 AM

Smallest possible valid PE executable is between 97 and 133 bytes. So even in C++ you have long way to go from 2.5k.

C# cannot be used for this purpose since it uses CLR. If one used Java, then there could be one single .class file, no dlls or anything. While small, it relies on the 100MB+ VM just to start. If anything, it might be acceptable if one were to strip out everything possible, but that would still leave tens of megabytes.

DX features used are part of HAL, so they are essentially drivers. They are also standardized and typically used for shaders only.

Using C# for demo-like projects also doesn't bring any benefits. There is no C# or even C++ code in such projects. They are just a loader for shaders. So there's a stub which does the minimum a runnable app needs to do, initializes the DX, then passes the big shader text file to it and that's it.

If doing CPU code, then assembly is where it's at. While no longer useful for general programming, compilers today can be beaten hard by someone with adequate knowledge. Especially when optimizing for size (the extreme type), there are plenty of tools compilers simply do not make use of, especially on newer CPUs with abundance of registers.

### #7Martins Mozeiko  Members

Posted 10 January 2012 - 01:09 PM

But there doesn't seem to be a way to include a static library into C# code, and my goal is to create a single file package.

You can merge multiple assemblies into one using one of these tools:
http://research.microsoft.com/en-us/people/mbarnett/ilmerge.aspx

Not sure if they work C++/CLI. If not, then another option would be swap SlimDX with SharpDX. The latter is pure C# library.

### #8Gavin Williams  Members

Posted 11 January 2012 - 05:02 PM

@NightCreature83 @Martins Mozeiko - I don't understand how C# can be independant of CLI (CLR specifically), isn't it a CLR language. So isn't all C# code compiled to CLI/CLR.

Let me describe how i currently 'think' of the difference between SlimDX and SharpDX : SlimDX uses System.Runtime.InteropServices to Import the C++ dll's from DirectX, in the normal way that I might access a C++ native function. While SharpDX uses a special magic source concocted at 4am by some crazed demo coder who knew there was a faster way to do this !! This might not be exactly correct, but I'm sure it's close to the mark.

### #9Martins Mozeiko  Members

Posted 11 January 2012 - 05:25 PM

C# is compiled to IL, not CLI/CLR (that's different concept).
C++/CLI is compiled to IL, or native code, or both of them (in mixed assemblies)

And that's not entirely correct regarding SlimDX vs SharpDX.
They both call com methods directly - only difference is that SlimDX is calling them through C++/CLI using calli, but SharpDX using calli IL instruction in pure C# - in generated IL asm instructions look very alike for both of them. SlimDX2 will be very similar in SharpDX in this matter.

### #10Gavin Williams  Members

Posted 11 January 2012 - 07:24 PM

@Martins Mozeiko - thanks for those links, which led me to finding this article on imbedding dlls into the assembly as a resource !

### #11Martins Mozeiko  Members

Posted 11 January 2012 - 07:27 PM

Well compared to C/C++/native world, that is more like embedding dll file in your exe file, and then loading this dll file from memory, instead of disk. Of course that also works, not really efficient, but works.
Using Mono.Linker/il-repack/ilmerge is much better, imho.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.