From: Mathieu Bouchard Date: 2005-09-16T04:33:25+09:00 Subject: Re: array sharing On Fri, 16 Sep 2005, mathew wrote: > You can use realloc to make an existing allocated chunk of memory larger, but > it always extends rightwards. Most of the time realloc will fail to extend and instead will malloc/memcpy/free the stuff for you. This is because Ruby does a lot of dynamic allocation and so it's very easy to have an extra malloc done in between a malloc and the realloc of it, and very often the extra malloc blocks the extensibility of it. It's memory fragmentation at work. This is also why it's better to use the exponential reallocation technique that Perl/Ruby/Python are using, because you can't expect to get O(1) realloc on average. realloc is enough of a failure that C++ doesn't bother providing an equivalent to it in the same way that the new/new[]/delete/delete[] operators are in C++. ____________________________________________________________________ Mathieu Bouchard - t�l:+1.514.383.3801 - http://artengine.ca/matju Freelance Digital Arts Engineer, Montr�al QC Canada