Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2007

Tip: Looking for answers? Try searching our database.

Simple code doesn't work on two systems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sourcerer - 17 Jan 2007 18:00 GMT
I wrote this very simple code in .NET VC++. I compiled it on my system, and
tried to run it on my friend's computer (he doesn't have the compiler). We both
have Windows XP Professional. I have .NET framework 2.0, and he had 1.0 and it
didn't work; then he installed 2.0 and it still didn't work; so he tried with
2.1 and it didn't work, then 3.0 and nothing still worked. I have Intel Centrino
Mobile (laptop computer), and he has Intel Pentium 4 (desktop computer). His
system reported an error that it cannot execute the program because of invalid
configuration. Why doesn't it work?

Here is the code I wrote, if it would mean anything:

#include <stdlib.h>

int main(void) {
int *a;
while (1) {
 a = (int *) malloc(100000 * sizeof(int));
}
return 0;
}

Signature

"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Ben Voigt - 17 Jan 2007 18:29 GMT
>I wrote this very simple code in .NET VC++. I compiled it on my system, and
>tried to run it on my friend's computer (he doesn't have the compiler). We
[quoted text clipped - 4 lines]
>(desktop computer). His system reported an error that it cannot execute the
>program because of invalid configuration. Why doesn't it work?

Did you do a release compile?  The debug compile in C++ requires debug
libraries that are only present when the compiler is installed.

> Here is the code I wrote, if it would mean anything:
>
[quoted text clipped - 7 lines]
> return 0;
> }
Sourcerer - 18 Jan 2007 15:24 GMT
>>I wrote this very simple code in .NET VC++. I compiled it on my system, and
>>tried to run it on my friend's computer (he doesn't have the compiler). We
[quoted text clipped - 7 lines]
> Did you do a release compile?  The debug compile in C++ requires debug
> libraries that are only present when the compiler is installed.

Do you mean by going to Build->Compile in the menu (or pressing Ctrl+F7)? I did
that, but it doesn't work.

Signature

"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Ben Voigt - 18 Jan 2007 15:40 GMT
>>>I wrote this very simple code in .NET VC++. I compiled it on my system,
>>>and tried to run it on my friend's computer (he doesn't have the
[quoted text clipped - 11 lines]
> Do you mean by going to Build->Compile in the menu (or pressing Ctrl+F7)?
> I did that, but it doesn't work.

I mean select "Release" as the current build configuration.  After you
compile, what directory does the .exe appear in?  If it's a Debug directory,
then it won't run on any computer without the compiler installed.  Note that
the directory name isn't what counts, it's just a good indicator under the
default project options.

The build configuration appears on the "Standard" toolbar in Visual Studio
2005.
Sourcerer - 24 Jan 2007 20:31 GMT
>>>>I wrote this very simple code in .NET VC++. I compiled it on my system, and
>>>>tried to run it on my friend's computer (he doesn't have the compiler). We
[quoted text clipped - 19 lines]
> The build configuration appears on the "Standard" toolbar in Visual Studio
> 2005.

OK, that solved the problem with the error. The program now runs, but is
terminated by Windows. Windows reports being low on Virtual Memory.

Now I know for a fact that my roommate has his Virtual Memory size set to zero.
However, what I don't understand is why the program won't run, given that he has
1.7GB of RAM free most of the time (idle Windows only use about 300MB). Why
won't Windows use physical memory, but instead insist on using virtual memory
for this program? Other programs run just fine on his computer.

Signature

"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Willy Denoyette [MVP] - 24 Jan 2007 20:48 GMT
>>>>>I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to
>>>>>run it on my friend's computer (he doesn't have the compiler). We both have Windows XP
[quoted text clipped - 25 lines]
> memory, but instead insist on using virtual memory for this program? Other programs run
> just fine on his computer.

while (1) {
 a = (int *) malloc(100000 * sizeof(int));
}

Not surprising, this is an endless loop, you keep allocating memory until all your VAS is
exhausted. What did you expect from this code?

Willy.
Sourcerer - 24 Jan 2007 21:00 GMT
>>>>>>I wrote this very simple code in .NET VC++. I compiled it on my system,
>>>>>>and tried to run it on my friend's computer (he doesn't have the
[quoted text clipped - 37 lines]
> Not surprising, this is an endless loop, you keep allocating memory until all
> your VAS is exhausted. What did you expect from this code?

No, you misunderstood. It's supposed to be an endless loop. However, the program
doesn't even begin execution. We were monitoring the performance in Task
Manager, to see how the memory gets allocated. On my system, the memory is
properly allocated until it is all gone, and then I terminate the execution by
force. On his system, nothing gets allocated. The performance meters don't show
any memory being allocated at all.

My question is, what does this have to do with Virtual Memory? I want to occupy
physical memory, not virtual.

Signature

"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Nathan Mates - 24 Jan 2007 21:43 GMT
>My question is, what does this have to do with Virtual Memory? I
>want to occupy physical memory, not virtual.

  So does everybody. But, when every app wants a lot of physical
memory, then something's gotta give. Virtual memory is the way of
fulfilling the promises made to each app, allowing them to share the
physical memory. Consider virtual memory the security for a loan
you're getting.

Nathan Mates

--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/ 
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
Sourcerer - 24 Jan 2007 22:13 GMT
>>My question is, what does this have to do with Virtual Memory? I
>>want to occupy physical memory, not virtual.
[quoted text clipped - 4 lines]
> physical memory. Consider virtual memory the security for a loan
> you're getting.

Something has to go wrong eventually, yes, but why is the program terminated
immediately?
Why doesn't the system allocate physical memory when it is available, and only
when it's running out go tamper with virtual memory?

Signature

"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/

Ben Voigt - 24 Jan 2007 23:23 GMT
>>>My question is, what does this have to do with Virtual Memory? I
>>>want to occupy physical memory, not virtual.
[quoted text clipped - 9 lines]
> Why doesn't the system allocate physical memory when it is available, and
> only when it's running out go tamper with virtual memory?

Only kernel-mode code can use physical memory, all user code uses virtual
memory which can be mapped into physical memory or into the swapfile (also
called pagefile).  You can't disable virtual memory, the VMM is essential to
any modern OS because it does stack allocation, process isolation, and a
host of other stuff that's not related to the swapfile.  You can only
disable the swapfile.  Some things can still be purged temporarily from
physical ram even without a swapfile, specifically read-only segments which
are mainly code (because the system can always get them back from disk).
That's one reason you can't delete a program that's running.

In fact, with 1.7GB of physical ram, you are as likely to run out of virtual
memory space (2 GB limit, which can be fragmented leaving holes, and even
though you haven't much fragmentation in your allocation pattern, the DLL
load addresses cause some holes in your address space) as physical.

Why the program terminates immediately I can't quite say.  How do you know
it isn't running?  On a fast processor it could finish before task manager
ever notices it.  Perhaps if you write to a file at the beginning of the
program, you can find out if it ever starts up.  You could also log after
each allocation to find out how many times the loop runs.  Make sure you
flush the file after each write, otherwise the runtime library will cache
your messages in memory, and they'll be lost when the error occurs.
Willy Denoyette [MVP] - 25 Jan 2007 00:48 GMT
>>>>>>>I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to
>>>>>>>run it on my friend's computer (he doesn't have the compiler). We both have Windows
[quoted text clipped - 38 lines]
> gone, and then I terminate the execution by force. On his system, nothing gets allocated.
> The performance meters don't show any memory being allocated at all.

If you run this on a system that is able to allocate all available VAS, before taskman is
showing the memory counter's value, you won't see anything *unusual*, more your program will
probably prevent Taskman from updating the UI in a timely fashion, because your program pegs
the CPU and the Memory system.
Beware that the smallest interval between the fetches is 1 second, fast systems are able to
allocate much more RAM than available on most systems within one second.
To illustrate what I'm saying, add a Sleep(10) call between each malloc and watch Taskman.

> My question is, what does this have to do with Virtual Memory? I want to occupy physical
> memory, not virtual.

You will occupy physical memory, but this is not under your control, neither will you
allocate physical memory only by calling malloc, you need to write to this memory before
virtual memory (reserved) turns into physical (comitted).

Willy.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.