From: Emmanuel Stapf [ES] on
Hi,

Is there an equivalent to the `limit' functionality of UNIX on Windows?
Basically I'm trying to test the behavior of my program when it runs out
of memory but because I have way to much available memory it takes a
very long time and trashes my system pretty badly. If I could limit the
memory usage to 100MB it would not trash my system and I'd be able to
test my program.

Any hints?
Thanks,
Manu
From: Jeroen Mostert on
Emmanuel Stapf [ES] wrote:
> Is there an equivalent to the `limit' functionality of UNIX on Windows?
> Basically I'm trying to test the behavior of my program when it runs out
> of memory but because I have way to much available memory it takes a
> very long time and trashes my system pretty badly. If I could limit the
> memory usage to 100MB it would not trash my system and I'd be able to
> test my program.
>
This is a little involved in Windows. AFAIK you can't really limit processes
individually (SetProcessWorkingSetSize() notably does *not* do this), but
you can do so for processes enlisted in a job (introduced in Windows 2000).

You can create a one-process job (through CreateJobObject() and
AssignProcessToJobObject()) and limit the memory consumption of the job with
SetInformationJobObject() (using the JOBOBJECT_EXTENDED_LIMIT_INFORMATION
structure). I haven't actually tested this approach myself, so YMMV.

--
J.
From: Kerem Gümrükcü on
Dear Emmanuel,

>I have way to much available memory

you dont have a limit on processes on a windows system and
it does not stop on your physical machines real memory limit.
I am sure, you know this, but many many people, i must
confess, sometimes me including simply forget, that you are working
with virtual memory on windows system, which is only
limited by your paging files size and the processor adressing
mode, either 32 bit, 64 bit any for some special systems even
more,...

Having lots of physical RAM Memory and a good tuned and
intelligent modified system caching settings made for the
operating system (fast drives, buts another toipc) can decrease
the swapping of memory from/to swapfile on the system.

Read this about the address space stuff you need to know:

[Memory Limits for Windows Releases]
http://msdn.microsoft.com/en-us/library/aa366778.aspx

The memory consumption for your application and all the
data you get by apps like Process Explorer, TaskManager,etc
are NOT the real memory amount your application covers. I
am pretty sure, that someone here can explain you this in
more detail,...

If your app really consumes huge amounts of memory,
then maybe you have to deal with intelligent garbage collection
allocation/freeing memory that is not used anymore or simply
have a second look over your code and optimize by redesigning
things and profilling or maybe some compiler flags may also help,...

Regards

Kerem

--
-----------------------
Beste Gr�sse / Best regards / Votre bien devoue
Kerem G�mr�kc�
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."
"Emmanuel Stapf [ES]" <manus(a)newsgroups.nospam> schrieb im Newsbeitrag
news:ufwekgK2IHA.1772(a)TK2MSFTNGP03.phx.gbl...
> Hi,
>
> Is there an equivalent to the `limit' functionality of UNIX on Windows?
> Basically I'm trying to test the behavior of my program when it runs out
> of memory but because I have way to much available memory it takes a very
> long time and trashes my system pretty badly. If I could limit the memory
> usage to 100MB it would not trash my system and I'd be able to test my
> program.
>
> Any hints?
> Thanks,
> Manu

From: Louis on
Emmanuel Stapf [ES] wrote:
> Hi,
>
> Is there an equivalent to the `limit' functionality of UNIX on Windows?
> Basically I'm trying to test the behavior of my program when it runs out
> of memory but because I have way to much available memory it takes a
> very long time and trashes my system pretty badly. If I could limit the
> memory usage to 100MB it would not trash my system and I'd be able to
> test my program.
>
> Any hints?
> Thanks,
> Manu

One way is to have your own Memory Manager, maybe one that uses the Heap
which you have place limits.

By having your own MM, you can simulate failure and test/design your
memory failure handling for your processes and threads by returning NULL
for your allocations and/or throwing exceptions.

As a side note..... Since Windows is a virtual memory system, the odds
are very high if you are experiencing problems, it is more likely than
not, that you are clobbering memory - buffer overflow or underflow.
These are generally the #1 reasons for memory bugs (and not releasing
pointers too).

There are many heap managers out there, free and commercial. I highly
recommend to find one and use it because it can really help solve these
"hidden" issues.

--
From: Pavel A. on
"Emmanuel Stapf [ES]" <manus(a)newsgroups.nospam> wrote in message
news:ufwekgK2IHA.1772(a)TK2MSFTNGP03.phx.gbl...
> Hi,
>
> Is there an equivalent to the `limit' functionality of UNIX on Windows?
> Basically I'm trying to test the behavior of my program when it runs out
> of memory but because I have way to much available memory it takes a very
> long time and trashes my system pretty badly. If I could limit the memory
> usage to 100MB it would not trash my system and I'd be able to test my
> program.
>
> Any hints?
> Thanks,
> Manu

Google for this message - this may be what you need.

~~~~~~~~~~~~~
From: "Ulrich Eckhardt"
Sent: Wednesday, May 28, 2008 11:22
Newsgroups: microsoft.public.vc.language
Subject: Simulating out-of-memory

For all that want to see how their code behaves when it runs out of memory,
here's a small piece of code:
.............
~~~~~~~~~~~

Regards,
--PA