Method: ContentData::ContentData#to_file
- Defined in:
- lib/content_data/content_data.rb
#to_file(filename) ⇒ Object
Write content data to file. Write is using chunks (for both content chunks and instances chunks) Chunk is used to maximize GC affect. The temporary memory of each chunk is GCed. Without the chunks used in a dipper stack level, GC keeps the temporary objects as part of the stack context.
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/content_data/content_data.rb', line 277 def to_file(filename) content_data_dir = File.dirname(filename) FileUtils.makedirs(content_data_dir) unless File.directory?(content_data_dir) File.open(filename, 'w') { |file| file.write("#{@contents_info.length}\n") contents_enum = @contents_info.each_key content_chunks = @contents_info.length / CHUNK_SIZE + 1 chunks_counter = 0 while chunks_counter < content_chunks to_file_contents_chunk(file,contents_enum, CHUNK_SIZE) GC.start chunks_counter += 1 end file.write("#{@instances_info.length}\n") contents_enum = @contents_info.each_key chunks_counter = 0 while chunks_counter < content_chunks to_file_instances_chunk(file,contents_enum, CHUNK_SIZE) GC.start chunks_counter += 1 end } end |