Memory Usage

  • Thread starter Thread starter IsRaEl
  • Start date Start date
I

IsRaEl

Hello Everyone..

Why when i build a REAAALY simples Console app with C#, when i compile
using the realese method and execute, it already occupies almost 7mb of
memory???

as simple as that!!
for(int i = 0; i<= 1000; i++)
for(int j = 0; j<= 1000; j++)
Console.WriteLine(i + "." + j);

How to make realy light programs...like some Google programs that use
600kb...

Thanks!
 
You are not actually _using_ 7mb of memory there ... memory is allocated in
chunks ... you then instantiate objects using bits of these chunks.. When
the application starts up it gets memory for you to use.

You also have the overhead in the runtime to contend with. Quite simply C#
is the wrong tool to write a program with 600k of overhead.

Cheers,

Greg
 
IsRaEl,

Because you are paying for garbage collection, memory management, etc,
etc.
 
It all depends on your definition of "really light".

At one end of the spectrum is Assembly Language. That's gonna be pretty
light.

At the other end is Java and .Net, both of which require a very complex
runtime.

In the middle somewhere is C and C++. These two arean't always as light as
they seem - there are all sorts of runtime libraries needed depending on the
environment in which you're running.

I don't really know where Python sits, but it's probably somewhere closer to
Java and .NET than Assembly language.
 
IsRaEl said:
To write really light apps i should do it directly with C++ or maybe
Python??

C is often significant lighter than C++.

Arne
 
Arne Vajhøj said:
C is often significant lighter than C++.

What do you base that on? C and C++ use variations of the same compiled. C++
code can compile as tightly or almost as tightly as C code. There's very
little difference in the size of the code generated. What libraries you use
may have a big impact, but there's almost none between the two languages.
 
Fredo said:
What do you base that on? C and C++ use variations of the same compiled. C++
code can compile as tightly or almost as tightly as C code. There's very
little difference in the size of the code generated. What libraries you use
may have a big impact, but there's almost none between the two languages.

Experience.

Try compile hello world in C and C++ and compare sizes.

Libraries, templates and the OO style create bigger programs.

Arne
 
Back
Top