osgEarth的Rex引擎原理分析(三十一)osgEarth::TerrainLayer中的_memCache(osgEarth::MemCache)详解

本文详细分析了osgEarth的Rex引擎中内存缓存系统,重点探讨了osgEarth::MemCache的实现,包括它的内部结构如MemCacheLRU,以及如何在数据库pager和地形图层中使用缓存进行瓦片数据的快速读写。同时,文章列举了一系列后续待分析的问题,涵盖了osgEarth的多个核心组件和概念。
摘要由CSDN通过智能技术生成

目标:(二十一)中的问题66

继承关系:

osgEarth::Cache

    osgEarth::MemCache

cache中的数据是通过cachebin来实现存放的,cachebin有两种,继承关系为:

osgEarth::CacheBin

     MemCacheBin(osgEarth/MemCache.cpp)

在osgEarth::Cache中有维护这osgEarth::CacheBin的map表,osgEarth::CacheBin其实就是最终的缓存数据,具体数据由其成员osg::ref_ptr<osg::Referenced> _metadata来存放

osgEarth::MemCache中的CacheBin本质上是MemCacheBin,具体数据是在其MemCacheLRU _lru中存放,MemCacheLRU(typedef LRUCache<std::string, MemCacheEntry> MemCacheLRU)是一个osgEarth::LRUCache(Least-recently-used最近最少使用缓存类,很多操作系统中都有此种缓存类),值得注意的是LRUCache中既有map又有list,他们存放的数据是相同的,只所以要这样做,是因为map方便查找和存放,list方便定位较早的元素。

osgEarth/MemCache.cpp
    typedef std::pair<osg::ref_ptr<const osg::Object>, Config> MemCacheEntry;
    typedef LRUCache<std::string, MemCacheEntry> MemCacheLRU;
    struct MemCacheBin : public CacheBin
    {
        MemCacheLRU _lru;
    };

缓存的默认大小为16.

 

在osgDB::DatabasePager::DatabaseThread::run中处理请求时,会往图层的缓存中写入瓦片信息,在创建瓦片模型时会从缓存中读取缓存信息。

写入缓存过程

osgDB/DatabasePager.cpp
void DatabasePager::DatabaseThread::run()
{
            // assume that readNode is thread safe...
            ReaderWriter::ReadResult rr = readFromFileCache ?
                        fileCache->readNode(fileName, dr_loadOptions.get(), false) :
                        Registry::instance()->readNode(fileName, dr_loadOptions.get(), false);
}
osgEarth/MemCache.cpp
        bool write( const std::string& key, const osg::Object* object, const Config& meta, const osgDB::Options* writeOptions)
        {
            if ( object ) 
            {
                osg::ref_ptr<const osg::Object> cloned = osg::clo
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值