可能重复:
Boost序列化库升级
我正在尝试为C++应用程序找到序列化解决方案.我真的希望能够使用boost二进制序列化.如果我使用较旧版本的boost二进制序列化序列化对象,那么使用较新版本的boost库的应用程序是否总能读取它?反过来呢?boost对序列化库的向后/兼容性的理念是什么?
尝试交叉编译GDB(使用--with-python标志)时出现此错误:
checking for python: /usr/bin/python
checking for python2.7: no
configure: error: python is missing or unusable
Run Code Online (Sandbox Code Playgroud)
我确保安装了python2.7 /usr/bin.我甚至删除了包并再次安装它.我试着用--with-python=/usr/bin和--with-python=/usr/local,但没有运气.虽然我已经安装了2.7但我肯定知道.有什么想法吗?
我在具有 1 个 REST 端点的 AWS API Gateway 中创建了一个 API。REST 端点调用用 C# 编写的 Lambda 函数。我还创建了一个 AWS Cognito 用户池。我想要做的是将 AWS Cognito 与 AWS Gateway API 集成,以便当未经身份验证的用户尝试调用 REST API 时,API 会将他们重定向到 AWS Cognito 的内置登录页面。目前,我已经将这两个集成在一起,但是当我尝试调用 REST API 时,它只是显示一条未经授权的消息。我希望它在那时重定向到登录页面,而不是显示该消息。我已经阅读了很多 AWS 文档,但不知道我错过了什么。我该怎么做呢?
我接受了软件开发人员职位的面试。那是电话面试。被问到这个问题,它一直困扰着我一整天
面试官让我想出一个在单词搜索网格上查找单词的通用方法。为简单起见,无需担心内存限制或在网格上对角搜索(从左到右,从上到下)。
我能想到的最好方法是在网格程序启动时创建一个哈希映射(在每次调用单词搜索之前)......让它创建一个字符=> row,col indices的哈希映射。这样你就可以在 O(1) 时间内执行初始扫描。然后从那里基本上从左到右或从上到下扫描。
我从他那里得到的印象是有一个更好的解决方案,而我还没有。解决此类问题的最快算法是什么?
更新:
我正在开发一个性能非常关键的程序.我有一个未排序的结构矢量.我需要在这个向量中执行许多搜索操作.所以我决定将矢量数据缓存到这样的地图中:
std::map<long, int> myMap;
for (int i = 0; i < myVector.size(); ++i)
{
const Type& theType = myVector[i];
myMap[theType.key] = i;
}
Run Code Online (Sandbox Code Playgroud)
当我搜索地图时,程序其余部分的结果要快得多.然而,剩下的瓶颈是地图本身的创建(平均花费大约0.8毫秒来插入约1,500个元素).我需要想办法减少这个时间.我只是插入一个long作为键和一个int作为值.我不明白为什么这么久.
我的另一个想法是创建一个向量的副本(不能触及原始的一个),并以某种方式执行比std :: sort更快的排序(它需要太长时间才能对它进行排序).
编辑:
对不起大家.我的意思是说我正在创建一个std :: map,其中键是long,值是int.long值是struct的键值,int是向量中相应元素的索引.
此外,我做了一些调试,并意识到矢量根本没有排序.这完全是随机的.所以做一些像stable_sort这样的东西是行不通的.
另一个更新:
谢谢大家的回复.我最终创建了一个对的向量(std :: vector of std :: pair(long,int)).然后我按长值对矢量进行排序.我创建了一个自定义比较器,仅查看该对的第一部分.然后我使用lower_bound来搜索该对.这就是我做到这一切的方式:
typedef std::pair<long,int> Key2VectorIndexPairT;
typedef std::vector<Key2VectorIndexPairT> Key2VectorIndexPairVectorT;
bool Key2VectorIndexPairComparator(const Key2VectorIndexPairT& pair1, const Key2VectorIndexPairT& pair2)
{
return pair1.first < pair2.first;
}
...
Key2VectorIndexPairVectorT sortedVector;
sortedVector.reserve(originalVector.capacity());
// Assume "original" vector contains unsorted elements.
for (int i = 0; i < originalVector.size(); ++i) …Run Code Online (Sandbox Code Playgroud) 我理解为什么我得到了我得到的错误(称为纯虚函数).我试图从我的基类的析构函数中调用纯虚函数,如下所示.但是,我不知道如何重写我的代码以防止这种情况发生.以下是基类和派生类(无论如何相关部分):
基类:
TailFileManager::TailFileManager(const std::string &filename, const int fileOpenPeriod_ms)
: m_Stop(false)
{
m_WorkerThread.reset(new boost::thread(boost::bind(&TailFileManager::TailFile, this, filename, fileOpenPeriod_ms)));
}
TailFileManager::~TailFileManager()
{
m_Stop = true;
m_WorkerThread->join();
}
void TailFileManager::TailFile(const std::string &filename, const int fileOpenPeriod_ms)
{
std::ifstream ifs(filename.c_str());
while (! ifs.is_open())
{
boost::this_thread::sleep(boost::posix_time::milliseconds(fileOpenPeriod_ms));
ifs.open(filename.c_str());
}
ifs.seekg(0, std::ios::end);
while (! m_Stop)
{
ifs.clear();
std::string line;
while (std::getline(ifs, line))
{
OnLineAdded(line);
}
OnEndOfFile();
}
ifs.close();
}
Run Code Online (Sandbox Code Playgroud)
派生类:
ETSLogTailFileManager::ETSLogTailFileManager(const std::string &filename, const int heartbeatPeriod_ms)
: TailFileManager(filename, heartbeatPeriod_ms),
m_HeartbeatPeriod_ms(heartbeatPeriod_ms),
m_FoundInboundMessage(false),
m_TimeOfLastActivity(0)
{
}
ETSLogTailFileManager::~ETSLogTailFileManager()
{
}
void ETSLogTailFileManager::OnLineAdded(const …Run Code Online (Sandbox Code Playgroud) 假设我有这两个类:
public class A<T> where T : IEntityWithID, new()
{
private static EntityInfo entityInfo = B.GetEntityInfo(typeof(T));
private static IEnumerable TestCases
{
// Do work with entityInfo...
}
}
private static class B
{
private static IList<EntityInfo> entityInfoList = B.GetEntityList();
public static EntityInfo GetEntityInfo(Type type)
{
return entityInfoList.Single(e => e.Types.Contains(type));
}
private static IList<EntityInfo> GetEntityList()
{
// Builds a list of EntityInfo's...
}
}
Run Code Online (Sandbox Code Playgroud)
B类中的entityInfoList是否保证在A类中调用B.GetEntityInfo()之前进行初始化和填充?
我有一个带有以下签名的方法:
bool DoSomething();
Run Code Online (Sandbox Code Playgroud)
我想把它改成这个:
bool DoSomething(IList<int> newIDs);
Run Code Online (Sandbox Code Playgroud)
布尔值和ID列表彼此不相关.新方法包含一个包含新ID列表的额外输出.这是不好的做法吗?在这种情况下返回多个值的正确方法是什么?