allocate particular amount of memory to a ruby thread ?

P

Pokkai Dokkai

how to allocate particular amount of memory to a ruby thread or to a
ruby script?

for example suppose if i want to start a thread it should take 1 MB
memory only

Thread.start(memory=1024*1024*1024) do |t|

# some stuff here
end

is there anyway to do like this ?
 
J

Jano Svitok

how to allocate particular amount of memory to a ruby thread or to a
ruby script?

for example suppose if i want to start a thread it should take 1 MB
memory only

Thread.start(memory=1024*1024*1024) do |t|

# some stuff here
end

is there anyway to do like this ?

AFAIK, the memory is shared among threads, no matter whether system or ruby's.
The memory for the whole ruby process/script is allocated on demand,
with some initial amount.
This amount and growing ratio is compiled-in (at least for 1.8).
 
R

Robert Klemme

AFAIK, the memory is shared among threads, no matter whether system or ruby's.

Exactly. That's the whole point of threads.
The memory for the whole ruby process/script is allocated on demand,
with some initial amount.
This amount and growing ratio is compiled-in (at least for 1.8).

And there is no way to limit it. It might be possible to limit on a per
process base (depending on OS, see "ulimit -a") but not on a per thread
base. And there might be a limit on the stack size. But it does not
make sense to limit memory allocated by a thread because the memory is
shared and can be used from any thread.

Kind regards

robert
 
J

Jano Svitok

Exactly. That's the whole point of threads.


And there is no way to limit it. It might be possible to limit on a per

Pokkai, what's your primary goal/problem? Why do you want to limit the memory?
Maybe there's a solution if you can look at the problem from another angle.

J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top