From: William Djaja Tjokroaminata Date: 2002-08-19T22:28:14+09:00 Subject: Re: Data_Make_Struct Considered Dangerous? Reimer Behrends wrote: -------------------------------------------------- > This is inaccurate. Ruby only knows about the memory allocated via > ALLOC(), not of memory allocated via malloc(). So, Ruby's heuristic > as to when to start the next GC might be way off, and you might > use more physical memory than necessary. In the extreme case, Ruby > would not start garbage collecting before you run out of swap space. -------------------------------------------------- Please see my response to Joel. Isn't it that the maximum possible wasted memory is determined by GC_MALLOC_LIMIT, which has default values of 8 megabytes? As an example, suppose I have a total of 128 Mbytes of memory. My Ruby memory is 16.1 Mbytes and my C memory is 64 Mbytes. Isn't it that the total used memory will be 24 + 64 = 88 Mbytes? -------------------------------------------------- > Once memory has become static, there will be no more calls to the > garbage collector; hence no CPU overhead from the garbage collector, > either. -------------------------------------------------- Not if we use the pair ALLOC() & free() on our C side. In this case, because of ALLOC, the garbage collector will stil get invoked, even though the Ruby memory is static. However, there will no new Ruby memory released when the garbage collector is invoked, and therefore it is a waste. -------------------------------------------------- > A big flaw in your argument is that you assume that you can always take > over the duties of freeing memory yourself. That works if the allocated > memory is referenced only by a single object. If the reference gets > passed around, you'll essentially find that you're implementing memory > management yourself again, trying to find out if the malloc()ed memory > is still accessible. -------------------------------------------------- Oh yes, because I am writing in C, memory management is part of everyday life; it is not like that in Ruby or Java. About the references to Ruby objects, aren't they taken care of by the mark functions? -------------------------------------------------- > Note that Data_Wrap_Struct() can initiate garbage collection as well, > namely in rb_newobj(). It doesn't really make a difference. -------------------------------------------------- Agreed. The only difference is, we "reduce" the frequency by which the garbage collector is invoked. With Data_Make_Struct, the allocated memory is the sum of the requested in ALLOC plus that in rb_newobj(); with Data_Wrap_Struct, it is only rb_newobj() alone, which I hope is not too large. Regards, Bill