Re: [Patch] String and (repost) MemLeak
From:
Mathieu Bouchard <matju@...>
Date:
2003-03-04 18:08:48 UTC
List:
ruby-core #914
On Tue, 4 Mar 2003, Michal Rokos wrote: > > |You're probably right - if programmer wants garbage he gets it... But I > > |still think that setting proper len cost nothing and could make some > > |tired programmers happier. > > Cost is nothing, I agree. But if a programmer gets a zero length > > string even when I specified len to str_new(), he/she may confuse > > sometimes. > I think it's correct - lenght is zero, but capa is correct. The > reality is that string, that you created, is 0 bytes long - not X. So > when you do rb_str_cat (or any other) you'll get the right* result. the point of str_new(0,n) is to be able to create a string of a known length but for which the contents are not "known" in advance, or at least, not in a buffer. Once you fill the n chars of the string object you just allocated, then the creation process is finished and you don't have to set the len again! A len is not a capa and a capa is not a len. Disclaimer: i don't know shit ________________________________________________________________ Mathieu Bouchard http://artengine.ca/matju