From: William Djaja Tjokroaminata Date: 2002-08-17T05:37:29+09:00 Subject: Re: Data_Make_Struct Considered Dangerous? OK, one final thought/question. It seems that based on the responses so far, the usefullness of ALLOC is: 1) to free memory periodically 2) safe when out-of-memory Suppose we have a version of malloc that can also exit gracefully when out-of-memory, and therefore the only advantage of ALLOC is to free memory periodically (by invoking the garbage collector). Suppose in this Ruby/C world we divide the memory into "Ruby memory" and "C memory". Ruby memory is defined to be memory consumed by Ruby because of user's Ruby script and C memory is defined to be memory that is allocated/deallocated by the C programmer who is writing Ruby/C. To make discussion simpler, assume that the total memory used is stable during the life of the process. To be interesting, we assume that the C memory is dynamic, i.e., memory is continually being consumed (by using ALLOC() or malloc()) and being released (by using free). Then we have two possibilities regarding the Ruby memory: either static or dynamic. Ruby memory can become static because in the user Ruby script, once the script is completely parsed, there are no more new Ruby objects being created. Then, 1) When Ruby memory is dynamic, we don't need to use ALLOC to free memory periodically, because the garbage collector is already being called often by Ruby internals. If we use ALLOC, then the garbage collector is called even more often, which may result in execution performance degradation. 2) When Ruby memory is static, there is no real need to invoke the garbage collector. If we use ALLOC, then the garbage collecting is only an execution waste, because no new memory will actually be released. So, it seems that we should always use malloc (or its safe version) instead of ALLOC. What is the flaw in the above argument? (Sorry, plain response such as "it is stupid" is not acceptable.) If the above argument is accepted, then because Data_Make_Struct calls ALLOC explicitly, it also follows that Data_Wrap_Struct should be preferred to Data_Make_Struct. Regards, Bill