why lcc made programs excessively use memory?

This is a discussion on why lcc made programs excessively use memory? within the Windows Programming forums, part of the Platform Specific Boards category; Hello!
I made a chat server using lcc-win32, a compiler that I'm happy with, but yesterday I discovered a very ...

why lcc made programs excessively use memory?

Hello!

I made a chat server using lcc-win32, a compiler that I'm happy with, but yesterday I discovered a very unusual thing. A 21kB large executable server takes up ~1.8 MB of RAM as reported by Task Manager ! Now, I may be a control freak about memory, but this is just not acceptable. My application almost has no static data, basically binds a server socket, awaits incoming chat/connections through WM_USER+ messages(async select) , where I make CreateThread() to create thread which reads off data, redistribute it to other clients and ends. I make careful use of my memory, so there is NO memleaks . How can I find out what the hell is going on? Does anyone have an idea? Thanks in advance !

CreateThread creates a stack which by default is 1 MB. Perhaps there is a big culprit.

I was just reading documentation on pthread calls and I remembered that I did not explicitly set thread stack, maybe that's it! But, it is a stable 1,8MB usage *even* no thread is created - before incoming connection, that is. I'll look at that anyway, thanks for the hint!

I was just reading documentation on pthread calls and I remembered that I did not explicitly set thread stack, maybe that's it! But, it is a stable 1,8MB usage *even* no thread is created - before incoming connection, that is. I'll look at that anyway, thanks for the hint!

Just because your binary is 21 kilobytes doesn't mean there is only 21 kilobytes of code. Unless you never call any library functions, you are at the mercy of what the libraries do. And modern libraries aren't terribly concerned with using as little memory as possible.

Yes, it certainly would be unless you go out of your way to assign a smaller stack-size. Also, if your application is 21KB, then it's most likely importing quite a bit of functionality from DLL's, which in themselves will take up some memory.

It's also worth noting the point that Salem is indicating - there's two sizes of memory:
1. The virtual size, which is the "maximum of memory this application could use at present" - but it's not necessarily using all of that, because some of the memory is just "reserved" so that there's a known place to populate with physical memory should it be needed
2. The actual physical memory used. This is how much memory is ACTUALLY really taken up in the RAM memory in your machine.

One example of this is the stack(s) of the thread(s) in the system. The default size is 1MB. But most applications use only a few kilobytes of that stack, so there's no point in the OS actually giving physical for the whole 1MB. It will do that as the memory is needed. Likewise, DLL's that are only partly used will only be partly loaded - but the memory space for the entire DLL is being reserved at load-time, because it would be horribly complicated if we for some reason started to use some part of that memory for other purposes and then needed the rest of the DLL to be loaded.

Well,thank to you all !!! I've learn about things that I didn't pay much attention earlier.

Originally Posted by matsp

Yes, it certainly would be unless you go out of your way to assign a smaller stack-size. Also, if your application is 21KB, then it's most likely importing quite a bit of functionality from DLL's, which in themselves will take up some memory.

Likewise, DLL's that are only partly used will only be partly loaded - but the memory space for the entire DLL is being reserved at load-time, because it would be horribly complicated if we for some reason started to use some part of that memory for other purposes and then needed the rest of the DLL to be loaded.

Yes, it would be hard to convince unsuspecting program to update it's pointers and not to write all over DLL body =)

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.