使用MemoryMappedFile作为BinaryReader

时间:2015-06-01 13:42:57

标签: memory compact-framework

我使用MemoryMappedFile(MMF)将大文件放入内存。使用内存限制32MB。使用MMF加载50MB文件2-3秒。从MMF读取数据工作得很好而且速度很快。 对我来说唯一的问题是:我有很多项目,在很多地方使用BigEndianReader(派生自BinaryReader)。而不是重写代码 - 我更喜欢修改此类以使用MMF调用替换BinaryReader调用。有没有人知道如何从MMF创建strteam?我有MMF的IntPtr,但我不明白如何从中创建Stream。

1 个答案:

答案 0 :(得分:2)

您必须继承$this->load->library('googlemaps'); $config['cluster'] = TRUE; $config['zoom'] = 'auto'; $this->googlemaps->initialize($config); //$address[ ]=$add; //store your multiple address in array // _debug($address); foreach($data['detail'] as $add) { $p_address = $add['p_address']; $p_city = $add['p_city']; $p_state = $add['state_name']; $p_zipcode = $add['p_zipcode']; $finaladd = $p_address.', '.$p_city.', '.$p_state.', '.$p_zipcode; //_Debug($finaladd); $prepAddr = str_replace(' ','+',$finaladd); $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false'); $output= json_decode($geocode); $lat = $output->results[0]->geometry->location->lat; $long = $output->results[0]->geometry->location->lng; $marker = array(); $marker['position'] = $lat.','.$long; $marker['infowindow_content'] = $finaladd; $marker['icon'] = 'http://chart.apis.google.com/chart? chst=d_map_pin_letter&chld=A|e02222|000000'; $this->googlemaps->add_marker($marker); } $data['map'] = $this->googlemaps->create_map(); ,跟踪流的Stream和当前映射的细分:

Position

public class MmfStream : Stream { private IntPtr currentMap; private long mapOffset; private long mapSize; private long position; 基类要求您实现StreamRead方法,因此每当应用程序尝试读取或写入时,您都可以使用Write来复制数据来自当前映射的段。

如果流的Marshal.Copy超出映射的段,则创建新的映射并提供新映射的段的信息。您还必须处理必须从当前访问新映射视图的数据。类似的东西:

Position

(此代码段中可能存在一次性错误;它只是对该想法的说明)