PDA

View Full Version : limit memory allocation



magland
20th March 2007, 14:56
Is there a way to specify the maximum amount of memory an application is allowed to allocate... either programmatically or otherwise?

high_flyer
20th March 2007, 16:44
under linux you have the 'limit' command (per shell session as far as I remeber).
Don't know if you have something like that under windows.

magland
21st March 2007, 09:45
Could you give example usage? When I type
> man limit

for example on my Linux I don't get anything... is it a different command?

Thanks.

high_flyer
21st March 2007, 10:00
so its not installed on your system.
Install it.
I am sure it will be in your package manager.
http://www.nada.kth.se/cgi-bin/man?p=limit&s=1&ss=&M=&f=y

wysota
21st March 2007, 10:39
I think it should be "ulimit".

high_flyer
21st March 2007, 10:45
NAME
limit, ulimit, unlimit - set or get limitations on the sys-
tem resources available to the current shell and its descen-
dents:)
No the message is not too short.

wysota
21st March 2007, 11:00
"ulimit" is builtin into bash, so you don't need any packages to use it ;)

high_flyer
21st March 2007, 11:23
I stand corrected! :)

magland
22nd March 2007, 20:14
Do you think I could use

void QThread::setStackSize ( uint stackSize )

to limit the available memory in a cross-platform application?

But I'm worried about using, say, stackSize = 10 MB for an unsigned integer...

What does "stackSize" precisely mean anyway?

P.S. -- Great site!

wysota
22nd March 2007, 21:19
No, this will only limit the stack, whereas most of the memory is usually allocated on heap.

high_flyer
23rd March 2007, 09:21
What does "stackSize" precisely mean anyway?
Well, just as it is named - the stack size.
You might want to read about heap and stack.
http://en.wikipedia.org/wiki/Heap_%28programming%29
http://en.wikipedia.org/wiki/Stack_frame