Tuesday, May 1, 2012

나쁜 코드: 스트링 관련

   -- WARNING: bad code ahead!!  
   local buff = ""  
   for line in io.lines() do  
   buff = buff .. line .. "\n"  
   end  
Despite its innocent look, that code in Lua can cause a huge performance penalty for large files...

This problem is not peculiar to Lua: Other languages with true garbage collection, and where strings are immutable objects, present a similar behavior, Java being the most famous example. (Java offers the structure StringBuffer to ameliorate the problem.)

출처 : 11.6 – String Buffers

No comments:

Post a Comment