Re: [julia-users] Most effective way to build a large string?
On Friday, October 14, 2016 at 10:44:47 PM UTC, Páll Haraldsson wrote: > > On Friday, October 14, 2016 at 5:17:45 PM UTC, Diego Javier Zea wrote: >> >> Hi! >> I have a function that uses `IOBuffer` for this creating one `String` >> like the example. >> Is it needed or recommended `close` the IOBuffer after `takebuf_string`? >> > > I find it unlikely. > > help?> takebuf_string > search: takebuf_string > > takebuf_string(b::IOBuffer) > > Obtain the contents of an IOBuffer as a string, without copying. > Afterwards, the IOBuffer is reset to its initial state. > > reset means they take action, and could have closed if needed; IOBuffer is > an in-memory thing, even if freeing memory was the issue, then garbage > collection should take care of that. > Note, IOBuffer (in RAM) is not like a file in non-volatile memory (unlike RAM). > > > Since this thread was necromanced: > > @Karpinski: "The takebuf_string function really needs a new name." > > I do not see clearly that that has happened, shouldn't > > help?> takebuf_string > > show then? > > What would be a good name? Changing and/or documenting the above could be > an "up-for-grabs" issue. > @Steven: "Further, in this case, the "takebuf_string" function (or takebuf_array) isn't just conversion, it is mutation because it empties the buffer. So, arguably it should follow the Julia convention and append a ! to the name." > New function would just call the old function.. > >
Re: [julia-users] Most effective way to build a large string?
On Friday, October 14, 2016 at 5:17:45 PM UTC, Diego Javier Zea wrote: > > Hi! > I have a function that uses `IOBuffer` for this creating one `String` like > the example. > Is it needed or recommended `close` the IOBuffer after `takebuf_string`? > I find it unlikely. help?> takebuf_string search: takebuf_string takebuf_string(b::IOBuffer) Obtain the contents of an IOBuffer as a string, without copying. Afterwards, the IOBuffer is reset to its initial state. reset means they take action, and could have closed if needed; IOBuffer is an in-memory thing, even if freeing memory was the issue, then garbage collection should take care of that. Since this thread was necromanced: @Karpinski: "The takebuf_string function really needs a new name." I do not see clearly that that has happened, shouldn't help?> takebuf_string show then? What would be a good name? Changing and/or documenting the above could be an "up-for-grabs" issue. New function would just call the old function..
Re: [julia-users] Most effective way to build a large string?
Hi! I have a function that uses `IOBuffer` for this creating one `String` like the example. Is it needed or recommended `close` the IOBuffer after `takebuf_string`? Best! On Tuesday, February 17, 2015 at 1:47:08 PM UTC-3, Stefan Karpinski wrote: > > IOBuffer is what you're looking for: > > buf = IOBuffer() > for i = 1:100 >println(buf, i) > end > takebuf_string(buf) # => returns everything that's been written to buf. > > The takebuf_string function really needs a new name. > > On Tue, Feb 17, 2015 at 9:06 AM, Maurice Diamantini < > maurice.d...@gmail.com > wrote: > >> Hi, >> >> In Ruby, String is mutable which allows to build large strings like this: >> txt = "" >> for ... >> txt << "yet another line\n" >> end >> # do something with txt >> >> The Julia the (bad) way I use is to do: >> txt = "" >> for ... >> txt *= "yet another line\n" >> end >> # do something with txt >> >> Which is very slow for a big string (because it build a new more and more >> string at each iteration). >> >> So is there another way to do it (in standard Julia)? >> Or is there another type which could be used (something like a Buffer >> type or Array type)? >> >> Thank, >> -- Maurice >> > >
Re: [julia-users] Most effective way to build a large string?
El martes, 17 de febrero de 2015, 10:47:08 (UTC-6), Stefan Karpinski escribió: IOBuffer is what you're looking for: buf = IOBuffer() for i = 1:100 println(buf, i) end takebuf_string(buf) # = returns everything that's been written to buf. The takebuf_string function really needs a new name. Could that function just be called `string`? The current behaviour of string applied to an IOBuffer does not seem useful: julia i = IOBuffer() IOBuffer(data=Uint8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1) julia string(i) IOBuffer(data=Uint8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1) On Tue, Feb 17, 2015 at 9:06 AM, Maurice Diamantini maurice.d...@gmail.com javascript: wrote: Hi, In Ruby, String is mutable which allows to build large strings like this: txt = for ... txt yet another line\n end # do something with txt The Julia the (bad) way I use is to do: txt = for ... txt *= yet another line\n end # do something with txt Which is very slow for a big string (because it build a new more and more string at each iteration). So is there another way to do it (in standard Julia)? Or is there another type which could be used (something like a Buffer type or Array type)? Thank, -- Maurice
Re: [julia-users] Most effective way to build a large string?
Thank you very much Stefan, and sorry I reposted this question one hour later ! My reply is on this other thread: https://groups.google.com/forum/?fromgroups=#!topic/julia-users/3OEH-m3EKco%5B1-25-false%5D -- Maurice
Re: [julia-users] Most effective way to build a large string?
IOBuffer is what you're looking for: buf = IOBuffer() for i = 1:100 println(buf, i) end takebuf_string(buf) # = returns everything that's been written to buf. The takebuf_string function really needs a new name. On Tue, Feb 17, 2015 at 9:06 AM, Maurice Diamantini maurice.diamant...@gmail.com wrote: Hi, In Ruby, String is mutable which allows to build large strings like this: txt = for ... txt yet another line\n end # do something with txt The Julia the (bad) way I use is to do: txt = for ... txt *= yet another line\n end # do something with txt Which is very slow for a big string (because it build a new more and more string at each iteration). So is there another way to do it (in standard Julia)? Or is there another type which could be used (something like a Buffer type or Array type)? Thank, -- Maurice