C++ 映射缓存找不到条目
c++ Map cache not find entrys
我试图编写缓存的着色器存储,目前im使用Map中的Map,第一个映射保存了这对。 map_of_uniformlocations持有 .使用我当前的解决方案,它将始终转到 else 语句,而不是从地图中获取数据,我认为这是因为每次我应该更新它时都会插入一个新的map_of_uniformlocations地图,但现在我坚持如何做到这一点。任何指示将不胜感激
uniformCache = m_UniformCache[shaderID];
//if specified shader uniform can be found
auto uniformLocation = uniformCache.find(name);
if (uniformLocation != uniformCache.end())
{
//this is true for only one of the objects in the map
return uniformLocation->second;
}
else
{
unsigned int uniformGetLocation = glGetUniformLocation(shaderID, name.c_str());
if (uniformGetLocation == -1)
{
return -1;
}
//I think the problem is with this
uniformCache.insert(std::pair<std::string, unsigned int>(name, uniformGetLocation));
m_UniformCache.insert(std::pair<unsigned int, std::unordered_map<std::string, unsigned int>>(shaderID, uniformCache));
return uniformGetLocation;
}
使用单个地图
也许不是您要找的答案,但您应该能够只使用一张地图来解决此问题,而不是使用 2 张地图。
虽然使用地图地图当然是可能的,但只使用一张地图将有助于避免很多陷阱和错误。
使用std::tuple
定义映射将生成具有复合键的映射。
然后按如下方式定义映射:
using UniformLocationCacheMap = std::map< std::tuple<std::string, int>, UniformLocation>;
相关文章:
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 找不到QtResource文件中的文件
- VC++本机单元测试,找不到调试符号
- RegGetValue在当前用户下找不到名称
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- c++找不到具有相同哈希的无序集合元素
- 找不到以下加速库:boost_fiber
- 找不到 FLTK(缺少:FLTK_INCLUDE_DIR)
- 设置 Visual Studio for MPI: 找不到标识符错误
- "assimp/config.h"找不到,但它在文件夹中
- 链接器找不到在虚拟类 c++ 中访问的静态字段的符号
- C++系统找不到指定的文件错误
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- C++ 映射缓存找不到条目
- gss_init_sec_context返回“找不到凭据缓存”(Windows,C++)
- 在 DNS 缓存中找不到 Libcurl 主机名